您正在使用Atmel studio v6.1 for AVR32 controller(AT32UC3A0512)。我正在使用I2C与相机(NanoCam C1U)设备进行通信。请注意,由于当数据准备好驻留在I2C总线上的子系统时,摄像机会自动发送I2C消息,因此总线必须在I2C多主机模式下运行。因此不支持I2C从模式。
以下是I2C多主站通信的代码,可以将数据发送到摄像机,但无法从相机接收。请帮助我在下面的代码中找到错误。
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];
}
}