This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi everyone,
I can't use Tera Term in the same time of dubugging my code on CCS for an unknown reason (it previously worked but now it just don't...)
Anyway I just want to collect data from the accelerometer (BMA222) and the temperature sensor (TMP006) in order to treat the data.
To verify if my code works fine I just use the register map window from CCS.
So, I have troubles in the use of providing function I2C_IF_WRITE and I2C_IF_READ.
I manage to read from the I2C base adresses (accelerometer : 0x18 and temperature sensor : 0x41)
but I cannot :
- Write in the registers of the slave (even by using the function ProcessWriteRegCommand())
Typically, what I do is :
int main()
{
unsigned char aucDataBuf[8] ;
unsigned char ucDevAddr = 0x18
unsigned char ucLenRD = 8;
BoardInit();
PinMuxConfig();
/*
* ACCELEROMETER READING
*/
//
// I2C Init
//
I2C_IF_Open(I2C_MASTER_MODE_FST);
iRetVal = I2C_IF_Read(ucDevAddr, aucDataBuf, ucLenRD); // first read attempt : iRetVal = SUCCESS
char data_wr[8] = {0x01, 0x02,0x01, 0x02,0x01, 0x02,0x01, 0x02}; // non sens data for test
iRetVal = I2C_IF_Write(ucDevAdd,data_wr,ucLenWR, false); // writting attempt : iRetVal = SUCCESS
iRetVal = I2C_IF_Read(ucDevAddr, aucDataBuf, ucLenRD); // second read attempt : iRetVal = SUCCESS
return 0;
}
My code seems very simple to me, but no need to say I am quite new with I2C communication.
Also what I don't understand is :
- How can it works with 8-bits adresses provided in parameters of I2C_IF_READ & I2C_IF_WRITE functions ?
Shoudn't it be " I2C_IF_Read(ucDevAddr>>1, aucDataBuf, ucLenRD)" ? (it returns error)
Kind regards,
Yoann
Hi, Lecat Yoann
1. Tera Term doesn't work?
Answer: Do you make sure that the Port and the baud rate of Tera Term are right?
Does Tera Term work when you debug other examples?
2.You can see the Register Map in the datasheet of TMP006 and BMA222. For example, the Register Map of TMP006 is as below.
We can see that the ucRegOffset of Tambient is 0x01h, so we can use the function I2C_IF_WRITE and I2C_IF_READ as following (Just give a example about collectting data from the temperature sensor (TMP006) ):
int
ProcessReadRegTem()
{
unsigned char ucDevAddr = 0x41;
unsigned char ucRegOffset = 0x01;
unsigned char ucLenRD = 2;
//
RET_IF_ERR(I2C_IF_Write(ucDevAddr,&ucRegOffset,1,0));
//
// Read the specified length of data
//
RET_IF_ERR(I2C_IF_Read(ucDevAddr, &aucRdDataBuff[0], ucLenRD));
UART_PRINT("I2C Read Temperature complete\n\r");
//
// Display the buffer over UART on successful readreg
//
DisplayBuffer(aucRdDataBuff, ucLenRD);
return SUCCESS;
}
Datasheet of temperature sensor (TMP006):
Datasheet of accelerometer (BMA222) :
Hi David Bai !
Thanks for for this complete response.
I have already overcame the problems I had, but your response should works perfectly
and focused completely on the problem I ask help for.
My problems were :
1. Can't connect terminal while uploading the code onto cc3200 on CCS.
2. Can't read & write with API functions given in I2C_DEMO.
solutions :
Problem 1 :
Very simple, I was connecting the terminal before (or during) the code uploading on the cc3200 target on CCS.
In my case, I have to wait for the code uploading to be finished BEFORE connecting the terminal, then I can
connect the terminal and run the code step by step or full run (in debug mode).
Problem 2 :
For my use, I have modified the given API function in the main file of I2C_DEMO project.
Obviously I still use the I2C_write() & I2C_read() functions, now it works perfectly (see code below).
One issue I overcame (by testing) was that if you try to write '1' on a reserved bit, all the write operation
will be avorted, you have to write '0' on these bit positions.
Code that is working :
/*READ OPERATION TO A SPECIFIED REGISTER ADRESS*/
unsigned char ucDevAddr=0x18;//adresse I2C 0x18 = Accéléromètre
unsigned char ucRegOffset = 0x00;//offset voltage data
unsigned char ucRdLen = 2;
BoardInit();//init Board
PinMuxConfig();//Pins Configure
I2C_IF_Open(I2C_MASTER_MODE_FST);//Activation liaison I2C mode fast
iRetVal = I2C_IF_Write(ucDevAddr,&ucRegOffset,1,0);
iRetVal = I2C_IF_Read(ucDevAddr, &dataBuffVobj[0], ucRdLen);
/*WRITE OPERATION TO A SPECIFIED REGISTER ADRESS*/
unsigned char ucDevAddr=0x41;//adresse I2C 0x41 = Capteur Température
unsigned char ucRegOffset = 0x01;//offset temp data
unsigned char ucRdLen = 2;
BoardInit();//init Board
PinMuxConfig();//Pins Configure
I2C_IF_Open(I2C_MASTER_MODE_FST);//Activation liaison I2C mode fast
I2C_IF_Write(ucDevAddr,&aucDataBuf[0],ucWrLen,0);
So this is exactly the code you wrote in your response ...
I put this here in the case someone have same issue than me : )
But now I have issues for SPI communication with external sensors ...
If someone can help me I will be very greatfull, here is my post
Thanks,
Yoann