Hi all,
I am asking for your help because I am trying to send several bytes using the I2C protocol in a program wich makes use of 2 I2C modules, and looks that it gets stuck after sending the first byte when checking the BUSY bit in I2CMCS. The board I am programming is the TM4C123GH6PM.
Here is the block diagram:
And here is the diagram available in the board's Data Sheet:
And this is the code in charge of sending the array content:
If I am not wrong, I am correctly following the diagram, but I can't see what is going wrong, so any help is appreciated.
Thanks,
Javier
I am asking for your help because I am trying to send several bytes using the I2C protocol in a program wich makes use of 2 I2C modules, and looks that it gets stuck after sending the first byte when checking the BUSY bit in I2CMCS. The board I am programming is the TM4C123GH6PM.
Here is the block diagram:
And here is the diagram available in the board's Data Sheet:
And this is the code in charge of sending the array content:
C:
int touch_lcd_write(enum typeOfWrite type, char command_data[], short I2C, int len)
{
//Some code not related with the problem
i=0;
while(I2C1_MCS_R&I2C_MCS_BUSBSY);
I2C1_MSA_R =write_touch_addr; //Specify the slave address of the master and that the next operation is a Transmit
I2C1_MDR_R=command_data; // Register address
I2C1_MCS_R=0x03; // (START, RUN).
while(I2C1_MCS_R&I2C_MCS_BUSY != 0); //here gets stucked
//Check if an error happens
if(I2C1_MCS_R&I2C_MCS_ERROR) //Check the ERROR bit in the I2CMCS register to confirm the transmit was acknowledged.
{
//Send stop
I2C1_MCS_R=0x04;
if(I2C1_MCS_R&I2C_MCS_ARBLST)
{
return 1;
}
else
{
return 2;
}
}
i++;
while(i<len)
{
I2C1_MDR_R=command_data; // Register address
if(i==len-1)
{
//Last byte. Generate RUN and STOP
I2C1_MCS_R=0x05; //RUN,STOP
}
else
{
//Generate RUN as it is not the last byte
I2C1_MCS_R=0x01; //RUN
}
while(I2C1_MCS_R&I2C_MCS_BUSY != 0); //Wait until the transmiI2Con completes by polling the I2CMCS register's BUSBstart_Y bit until it has been cleared.
if(I2C1_MCS_R&I2C_MCS_ERROR) //Check the ERROR bit in the I2CMCS register to confirm the transmit was acknowledged.
{
if(I2C1_MCS_R&I2C_MCS_ERROR) //Check the ERROR bit in the I2CMCS register to confirm the transmit was acknowledged.
{
//Send stop
I2C1_MCS_R=0x04;
if(I2C1_MCS_R&I2C_MCS_ARBLST)
{
return 1;
}
else
{
return 2;
}
}
}
i++;
}
}
If I am not wrong, I am correctly following the diagram, but I can't see what is going wrong, so any help is appreciated.
Thanks,
Javier