-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add I2C library and example for CC2538 #677
Conversation
This file contais the define and function declarations to use the I2C peripheral of the CC2538 platform
This file contains the implementation of functions declared in i2c.h to allow to use the I2C peripheral of the CC2538 platform.
Add the i2c.c file to the CONTIKI_CPU_SOURCEFILES for compilation. It allow to use the I2C library in other projects.
This file is an exemple of I2C usage for the CC2538 platform. It can be used with a TCN75 and/or a SHT21 sensor.
This file is the Makefile for the i2c-example project. It enable the low power mode for the CC2538.
This file set the default target to be the cc2538dk for the i2c-example.
Add a function to print float (with value and precision for parameters), for the SHT21 measure.
Remove the STARTUP_CONF_VERBOSE = 0 line, because implicit when CC2538_CONF_QUIET = 1
Use the DEFINES= macro to assign value to configuration variables instead of juste variable=value
Change the print_float function to display the two number at same time. It improve the reliability for displaying over serial port.
This is a PR concurrent to #397. I have not compared these two PRs, but you will probably have to discuss with @areaarea in order to choose which parts of each PR are the best. Regarding the |
Temperature and relative humidity measurement for cave use case
Temperature and relative humidity measurement for cave use case
I have tested this driver with CC2538 and MPU9150 setup. No problems so far |
i2c_master_command(I2C_MASTER_CMD_SINGLE_RECEIVE); | ||
while(i2c_master_busy()) { | ||
} | ||
if(temp = i2c_master_error()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line causes GCC warnings to be emitted when -Wextra is used, as the single equals in a conditional is in many causes a bug (but not this case). You can silence it by wrapping up the conditional in a second set of parenthes:
if((temp = i2c_master_error())) {
Add parenthesis around assignement used as truth value
Uncomment the line 81, which make sûr the passed value is a boolean, to prevent slave address error
Add the volatile keyword line 19, to prevent the compiler from optimizing the loop variable
Rewrite the i2c_master_set_slave_address function
For a beginer like I am, it is worth checking charpter 20 on http://www.ti.com/lit/ug/swru319c/swru319c.pdf |
I can confirm that this works for my custom board with an SHT21. Thanks medmig! |
This code works pretty well on my custom cc2538 platform. However, I think it should be user configurable whether or not the internal pull up resistors are used. I know some i2c peripherals only work with external pull ups, but the rtc I use works with just the internal pull up resistors. |
Noted, thanks. I think that with those positive confirmations we can merge this, even if it doesn't have everything that one might desire. I'll have a closer look as soon as I get a chance in view of merging this ultimately. |
@wwhuang That would be a nice addition, but its interesting what you say that about some peripherals. Are you sure its not just the value of the pull-ups? What is the value you use? Usually weak pull-ups result in corrupted data, especially when you have many devices on the bus. |
Hi medmig, I have been using the code for a while, I was getting more resets from this code so I changed the following. while(i2c_master_busy()) {} to uint8_t
while_busy(void){
uint16_t count = 0;
uint16_t count_max = 1000;
while( (i2c_master_busy() && (count<count_max)) ){
count++;
clock_delay_usec(10);
}
if (count>=count_max)
return 1;
else
return 0 ;
} Also I havent figured out how to send bytes to a device. Should it be something like this? uint8_t
writeByte(uint8_t address, uint8_t reg, uint8_t val){
i2c_master_set_slave_address(address, I2C_SEND);
i2c_master_data_put(reg);
i2c_master_command(I2C_MASTER_CMD_BURST_SEND_START);
if (while_busy()) return I2CM_STAT_BUSBSY;
i2c_master_data_put(val);
if (while_busy()) return I2CM_STAT_BUSBSY;
return I2C_MASTER_ERR_NONE;
} Thanks!! |
Hi @dazhbog , Sorry I'm late, and I agree with you, because the waiting loop is an active loop, the watchdog may reboot. I have no sufficient experience to say if it's a good thing to had a timeout, and if the way you do this is the good way, but I think it can be a good idea (even if I think that the waiting loop should be finished (the I2C should be free) before the watchdog reboot). Also, there are differents way to send data to a device, depending on the number of bytes you want to send. I've written few examples, but if they didn't help you, I suggest that you read the TI CC2538's documentation to get more precisions about the differents way to send data. If you want to send more than 1 byte you will have to use the i2c_master_command function, combined with the I2C_MASTER_CMD_BURST_SEND_* defines. Otherwise, you can use the i2c_single_send function. I'm sorry if I'm confusing, but I'm not working on this project anymore, and I'm not an English native speaker. I'll try to answer faster if you have any other question. PS : I'm glad this code was usefull for someone :) |
Hi, @medmig. We're looking at this now and it seems to work fine. We'll probably open a new PR based on this one since you are not working on this. I see there is no license header in the .c file. Can you confirm that you're happy for this to be 3-clause BSD? |
Hi, @g-oikonomou . |
@g-oikonomou Has there been any progress on this? The CC2538 should probably have an I2C library, even if it's not perfect. |
… static and added burst modes
… static and added burst modes
… static and added burst modes
… static and added burst modes
… static and added burst modes
… static and added burst modes
Add one header file and one implementation file to use the I2C peripheral of the CC2538 platform.
Add a line in the CC2538 makefile to include the I2C library for compilation.
Also add an example to use the I2C library with two different sensors (TCN75 from Microchip and SHT21 from Texas Instruments).
This adaptation of I2C library was made by Mehdi Migault for the 4MOD Technology company, as part of an internship with the IT department of the "Institut Universitaire et Technologique" in La Rochelle.
Parts of the sources come from Contiki and Texas Instruments.
It include an example for the I2C library that work with two different I2C sensors, the TCN75 from Microchip and the SHT21 from Texas Instruments. It measure temperature and send the value over the serial port.