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.
Diff: targets/hal/TARGET_WIZNET/TARGET_W7500x/i2c_api.c
- Revision:
- 576:99a3d3d9c43f
- Parent:
- 567:a97fd0eca828
- Child:
- 601:248b0d2dd755
--- a/targets/hal/TARGET_WIZNET/TARGET_W7500x/i2c_api.c Wed Jun 24 09:45:13 2015 +0100 +++ b/targets/hal/TARGET_WIZNET/TARGET_W7500x/i2c_api.c Tue Jun 30 09:45:08 2015 +0100 @@ -31,12 +31,16 @@ #include "mbed_assert.h" #include "i2c_api.h" + #if DEVICE_I2C #include "cmsis.h" #include "pinmap.h" #include "PeripheralPins.h" +#include "wait_api.h" +#include "us_ticker_api.h" + /* Timeout values for flags and events waiting loops. These timeouts are not based on accurate values, they just guarantee that the application will not remain stuck if the I2C communication is corrupted. */ @@ -87,7 +91,8 @@ void i2c_frequency(i2c_t *obj, int hz) { - MBED_ASSERT((hz == 100000) || (hz == 400000) || (hz == 1000000)); + //MBED_ASSERT((hz == 100000) || (hz == 400000) || (hz == 1000000)); + MBED_ASSERT((hz == 100000)); I2cHandle = (I2C_TypeDef *)(obj->i2c); // wait before init @@ -95,19 +100,20 @@ conf.mode = I2C_Master; conf.master.timeout = LONG_TIMEOUT; + conf.master.prescale = 0x61; // Standard mode with Rise Time = 400ns and Fall Time = 100ns // Common settings: I2C clock = 48 MHz, Analog filter = ON, Digital filter coefficient = 0 - switch (hz) { - case 100000: - conf.master.prescale = 0x61; // Standard mode with Rise Time = 400ns and Fall Time = 100ns - break; - case 400000: - break; - case 1000000: - break; - default: - break; - } +// switch (hz) { +// case 100000: +// conf.master.prescale = 0x61; // Standard mode with Rise Time = 400ns and Fall Time = 100ns +// break; +// case 400000: +// break; +// case 1000000: +// break; +// default: +// break; +// } // I2C configuration I2C_Init(I2cHandle, conf); @@ -127,8 +133,9 @@ // Generate the STOP condition I2C_Stop(I2cHandle); I2C_Reset(I2cHandle); + obj->is_setAddress = 0; - + return 0; } @@ -137,12 +144,12 @@ I2cHandle = (I2C_TypeDef *)(obj->i2c); int count; int value; - + if(!obj->is_setAddress) { if( I2C_Start(I2cHandle, address, I2C_READ_SA7) == ERROR ) { - return -1; + return -1; } obj->is_setAddress = 1; obj->ADDRESS = address; @@ -155,52 +162,78 @@ // Read all bytes for (count = 0; count < (length-1); count++) { - if( (value = i2c_byte_read(obj, 0)) == -1) return value; + if( (value = i2c_byte_read(obj, 0)) == -1) { + return value; + } data[count] = (char)value; } if(stop){ - if( (value = i2c_byte_read(obj, 1)) == -1) return value; + if( (value = i2c_byte_read(obj, 1)) == -1) { + return value; + } data[count] = (char)value; - } + + i2c_stop(obj); + obj->is_setAddress =1; + count++; + } else{ - if( (value = i2c_byte_read(obj, 0)) == -1) return value; + if( (value = i2c_byte_read(obj, 0)) == -1) { + + return value; + } data[count] = (char)value; + count++; } - + return count; + } int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { I2cHandle = (I2C_TypeDef *)(obj->i2c); - int count; - + int count =0; + if(!obj->is_setAddress) { if( I2C_Start(I2cHandle, address, I2C_WRITE_SA7) == ERROR ) { - return -1; + return -1; } obj->is_setAddress = 1; obj->ADDRESS = address; - } + } else { I2C_Restart_Structure(I2cHandle, address, I2C_WRITE_SA7); obj->ADDRESS = address; + } for (count = 0; count < length; count++) { i2c_byte_write(obj, data[count]); + wait_us(1); } + + if(length == 0x00) + { + I2C_GPIO(); + i2c_byte_write(obj, 0xff); + GPIO_I2C(); + } // If not repeated start, send stop if (stop) { i2c_stop(obj); + } + else + { + i2c_reset(obj); + } - - return count; + return count; } int i2c_byte_read(i2c_t *obj, int last)