• AVR Freaks

Hot!SAMD51 I2C slave AMATCH interrupt

Author
tom.worldgn
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/12/18 20:12:11
  • Location: 0
  • Status: offline
2020/06/28 02:06:53 (permalink)
0

SAMD51 I2C slave AMATCH interrupt

Hi, 
    I used SAMD51J19 to implement a sensor-like device, it cannot into the AMATCH interrupt now, but DRDY and PREC is work fine.
This is the code that I initialize I2C slave:
{
 
    uint32_t mode = SERCOM1_REGS->I2CS.SERCOM_CTRLA & SERCOM_I2CS_CTRLA_MODE_Msk;
    if(SERCOM_I2CS_CTRLA_ENABLE_Msk & SERCOM1_REGS->I2CS.SERCOM_CTRLA){
        SERCOM1_REGS->I2CS.SERCOM_CTRLA &= ~SERCOM_I2CS_CTRLA_ENABLE_Msk;
        while(SERCOM1_REGS->I2CS.SERCOM_SYNCBUSY);
    }
    SERCOM1_REGS->I2CS.SERCOM_CTRLA = SERCOM_I2CS_CTRLA_SWRST_Msk | mode;
    while(SERCOM1_REGS->I2CS.SERCOM_SYNCBUSY);
    SERCOM1_REGS->I2CS.SERCOM_CTRLA = SERCOM_I2CM_CTRLA_MODE_I2C_SLAVE;
    SERCOM1_REGS->I2CS.SERCOM_CTRLB = SERCOM_I2CS_CTRLB_SMEN_Msk | SERCOM_I2CS_CTRLB_AACKEN_Msk;
    SERCOM1_REGS->I2CS.SERCOM_ADDR = SERCOM_I2CS_ADDR_ADDR(SENSOR_SLAVE_I2C_ADDR);
    SERCOM1_REGS->I2CS.SERCOM_INTENSET = SERCOM_I2CS_INTENSET_Msk;
    while(SERCOM1_REGS->I2CS.SERCOM_SYNCBUSY);
    SERCOM1_REGS->I2CS.SERCOM_CTRLA |= SERCOM_I2CS_CTRLA_ENABLE_Msk;
    ...
}
Interrupt code:
{
   if(0 != SERCOM1_REGS->I2CS.SERCOM_INTENSET){
        if(0 != SERCOM1_REGS->I2CS.SERCOM_INTFLAG){
            if(SERCOM1_REGS->I2CS.SERCOM_INTFLAG & SERCOM_I2CS_INTFLAG_AMATCH_Msk){
                ...
                SERCOM1_REGS->I2CS.SERCOM_CTRLB |= SERCOM_I2CS_CTRLB_CMD_Msk; 
            }
            if(SERCOM1_REGS->I2CS.SERCOM_INTFLAG & SERCOM_I2CS_INTFLAG_DRDY_Msk){
                if(SERCOM_I2CS_STATUS_DIR_Msk & SERCOM1_REGS->I2CS.SERCOM_STATUS){
                    ...
                }else{
                    ...
                }
                SERCOM1_REGS->I2CS.SERCOM_CTRLB |= SERCOM_I2CS_CTRLB_CMD_Msk;
            }
            if(SERCOM1_REGS->I2CS.SERCOM_INTFLAG & SERCOM_I2CS_INTFLAG_PREC_Msk){
                ...
            }
            SERCOM1_REGS->I2CS.SERCOM_INTFLAG = SERCOM_I2CS_INTFLAG_Msk;
        }
}
If I implement in PREC the code that was originally in AMATCH, it would have worked fine, but I think this is wrong way. How can I solve this problem correctly?
Thanks.
#1

1 Reply Related Threads

    tom.worldgn
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2019/12/18 20:12:11
    • Location: 0
    • Status: offline
    Re: SAMD51 I2C slave AMATCH interrupt 2020/06/29 19:21:37 (permalink)
    4 (1)
    The review of the forum is a bit slow for me, I have solved this problem.
    The key flag is "SERCOM_I2CS_CTRLB_AACKEN_Msk", If I use it, the AMATCH interrupt flag will not be set.
    The datasheet I read did not mention that this flag would affect the AMATCH interrupt.
    Hope it helps you. :)
     
    #2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5