mbed library sources
Dependents: Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more
Superseded
This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.
Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.
If you are looking for a stable and tested release, please import one of the official mbed library releases:
Import librarymbed
The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Revision 314:b682143dd337, committed 2014-09-11
- Comitter:
- mbed_official
- Date:
- Thu Sep 11 13:15:08 2014 +0100
- Parent:
- 313:b7d035234249
- Child:
- 315:1d806f4588f1
- Commit message:
- Synchronized with git revision 31f43a330576b420154e9459b856d93f92b5ed71
Full URL: https://github.com/mbedmicro/mbed/commit/31f43a330576b420154e9459b856d93f92b5ed71/
[nrf51822] avoid using a global variable and fix I2C read sequence
Changed in this revision
--- a/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/i2c_api.c Thu Sep 11 13:00:06 2014 +0100 +++ b/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/i2c_api.c Thu Sep 11 13:15:08 2014 +0100 @@ -30,8 +30,6 @@ {NC, NC, 0} }; -uint8_t addrSet = 0; - void i2c_interface_enable(i2c_t *obj) { obj->i2c->ENABLE = (TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos); @@ -97,7 +95,7 @@ { int status = 0; i2c_reset(obj); - addrSet = 0; + obj->address_set = 0; return status; } @@ -113,7 +111,7 @@ return 1; } } - addrSet = 0; + obj->address_set = 0; i2c_reset(obj); return 0; } @@ -137,8 +135,13 @@ int timeOut = 100000; if (last) { - obj->i2c->TASKS_STOP = 1; + // To trigger stop task when a byte is received, + // must be set before resume task. + obj->i2c->SHORTS = 2; } + + obj->i2c->TASKS_RESUME = 1; + while (!obj->i2c->EVENTS_RXDREADY) { timeOut--; if (timeOut<0) { @@ -146,14 +149,8 @@ } } obj->i2c->EVENTS_RXDREADY = 0; - *data = obj->i2c->RXD; - for (int i = 0; i<320; i++) { - } - - obj->i2c->TASKS_RESUME = 1; - return 0; } @@ -191,7 +188,7 @@ { int status, count, errorResult; obj->i2c->ADDRESS = (address >> 1); - obj->i2c->SHORTS = 0; + obj->i2c->SHORTS = 1; // to trigger suspend task when a byte is received obj->i2c->EVENTS_RXDREADY = 0; obj->i2c->TASKS_STARTRX = 1; @@ -266,14 +263,16 @@ int i2c_byte_write(i2c_t *obj, int data) { int status = 0; - if (!addrSet) { - addrSet = 1; + if (!obj->address_set) { + obj->address_set = 1; obj->i2c->ADDRESS = (data >> 1); if (data & 1) { obj->i2c->EVENTS_RXDREADY = 0; + obj->i2c->SHORTS = 1; obj->i2c->TASKS_STARTRX = 1; } else { + obj->i2c->SHORTS = 0; obj->i2c->TASKS_STARTTX = 1; } } else {
--- a/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/objects.h Thu Sep 11 13:00:06 2014 +0100 +++ b/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/objects.h Thu Sep 11 13:15:08 2014 +0100 @@ -53,6 +53,7 @@ PinName sda; PinName scl; int freq; + uint8_t address_set; }; struct analogin_s {