Aphoorva A
Aphoorva A

Reputation: 1

I2C multi master mode in AVR32 board

Hi am working in Atmel studio v6.1 for AVR32 controller (AT32UC3A0512). I am working on I2C to communicate with a camera (NanoCam C1U) device. Please note that since the Camera sends out an I2C message automatically when data is ready for a subsystem residing on the I2C bus, the bus must be operated in I2C multi-master mode. I2C slave mode is thus not supported.

Below is the code for I2C multi master communication, Am able to send data to the camera but am not able to receive from the same. Kindly, help me to find the bug in below code.

AVR32_TWI.CR.svdis = 1;     //slave disable
AVR32_TWI.CR.msen = 1;      //master enable
AVR32_TWI.MMR.dadr = 0x5;   //OBC AVR32 address

void cam_snap(void)
{
    const uint8_t CAMSnapCmd[2] = {0x84,0x65};
    uint8_t CamSnapCmdOutput[70];

    AVR32_TWI.CR.svdis=1;   //slave disable
    AVR32_TWI.CR.msen=1;        //master enable
    AVR32_TWI.MMR.dadr=0x6; //Camera slave device address.
    AVR32_TWI.MMR.mread = 0;    // write mode

    lPayloadTimeout = PAYLOAD_TIMEOUT ;
    AVR32_TWI.THR.txdata = CAMSnapCmd[0];
    while(AVR32_TWI.SR.txrdy!=1)
    {
        if(lPayloadTimeout == 0)
            return;
        else
            lPayloadTimeout--;
    }

    lPayloadTimeout = PAYLOAD_TIMEOUT ;
    AVR32_TWI.THR.txdata=CAMSnapCmd[1];
    while(AVR32_TWI.SR.txrdy!=1)
    {
        if(lPayloadTimeout == 0)
            return;
        else
            lPayloadTimeout--;
    }

    lPayloadTimeout = PAYLOAD_TIMEOUT ;
    while(AVR32_TWI.SR.txcomp!=1)
    {
        if(lPayloadTimeout == 0)
            return;
        else
            lPayloadTimeout--;
    }

    AVR32_TWI.SMR.sadr=0x5; //OBC Master address AVR32
    AVR32_TWI.CR.msdis=1;//master disable
    AVR32_TWI.CR.sven=1;//slave enable
    //AVR32_TWI.MMR.mread = 0;

    for(int j =0; j< 65; j++) 
    {
        lPayloadTimeout = PAYLOAD_TIMEOUT ;
        while(AVR32_TWI.SR.rxrdy!=1)
        {
            if(lPayloadTimeout == 0)
                return;
            else
                lPayloadTimeout--;
        }
        CamSnapCmdOutput[j] = AVR32_TWI.RHR.rxdata;
        uint8_t test_result = CamSnapCmdOutput[0];
    }
}

Upvotes: 0

Views: 164

Answers (0)

Related Questions