mbed library sources modify the rtc/i2c
Dependents: SSD1306_smart_watch
Fork of mbed-src by
Revision 577:545d200432a1, committed 2015-06-29
- Comitter:
- eunkyoungkim
- Date:
- Mon Jun 29 05:49:52 2015 +0000
- Parent:
- 576:c2b3bfe477a7
- Commit message:
- modify the i2c.c/i2c.h
Changed in this revision
--- a/targets/cmsis/TARGET_WIZNET/TARGET_W7500x/W7500x_i2c.c Mon Jun 29 04:14:49 2015 +0000 +++ b/targets/cmsis/TARGET_WIZNET/TARGET_W7500x/W7500x_i2c.c Mon Jun 29 05:49:52 2015 +0000 @@ -5,7 +5,7 @@ */ GPIO_InitTypeDef GPIO_InitDef; -void delay_us(int us); +void i2c_loop_us(int us); #define SCL GPIO_Pin_9 #define SDA GPIO_Pin_10 @@ -74,12 +74,6 @@ I2C_GenerateSTART(I2Cx,ENABLE); I2C_SendSlaveAddress(I2Cx,slave_address,(I2C_CTR)ctr); I2C_GenerateSTART(I2Cx,DISABLE); - - // printf("I2C0->TXR : %x\r\n", I2C0->TXR); - // printf("addr : %x, ctr : %x \r\n", slave_address, ctr); - //printf("%x, %x, %x\r\n", I2C0->PRER, I2C0->TSR, I2C0->CTR); - - ret=I2C_CheckEvent(I2Cx,I2C_ACKR); @@ -110,12 +104,12 @@ int8_t I2C_SendDataAck(I2C_TypeDef* I2Cx,uint16_t Data) { - buf[0] = Data; + buf[0] = Data; if(buf[0] == buf[1]) { I2C_GPIO(); WriteByte(Data); - delay_us(1); + i2c_loop_us(1); GPIO_I2C(); } else @@ -132,19 +126,16 @@ int I2C_ReceiveData(I2C_TypeDef* I2Cx, int last) { - - if(last) { I2C_AcknowledgeConfig(I2Cx,DISABLE); if( I2C_CheckEvent(I2Cx,I2C_ACKT) == ERROR ) { - return -1; + return -1; } } else if( I2C_CheckEvent(I2Cx,I2C_ACKT) == ERROR ) { return -1; } - return (uint8_t)I2Cx -> RXR; } @@ -544,6 +535,33 @@ } + +void WriteByte(uint8_t val) +{ + int i; + GPIO_TypeDef* GPIOx; + GPIOx = GPIOA; + + for(i=0;i<8;i++) + { + if((val << i) & 0x80){ + digitalWrite(GPIOx,SDA, Bit_SET); + }else{ + digitalWrite(GPIOx,SDA, Bit_RESET); + } + i2c_loop_us(1); + digitalWrite(GPIOx,SCL, Bit_SET); + i2c_loop_us(2); + digitalWrite(GPIOx,SCL, Bit_RESET); + } + digitalWrite(GPIOx,SDA, Bit_SET); + i2c_loop_us(1); + digitalWrite(GPIOx,SCL, Bit_SET); + i2c_loop_us(2); + digitalWrite(GPIOx,SCL, Bit_RESET); +} + + void digitalWrite(GPIO_TypeDef* GPIOx,uint16_t pin, uint16_t val) { @@ -558,56 +576,14 @@ } } -uint16_t digitalRead(GPIO_TypeDef* GPIOx,uint16_t pin) -{ - uint16_t bitstatus = 0x0000; - if((GPIOx->DATA & pin) != (uint32_t)Bit_RESET) - { - bitstatus = (uint8_t)Bit_SET; - } - else - { - bitstatus = (uint8_t)Bit_RESET; - } - - return bitstatus; -} - -void WriteByte(uint8_t val) +void i2c_loop_us(int us) { - int i; - GPIO_TypeDef* GPIOx; - GPIOx = GPIOA; - - for(i=0;i<8;i++) - { - if((val << i) & 0x80){ - digitalWrite(GPIOx,SDA, Bit_SET); - }else{ - digitalWrite(GPIOx,SDA, Bit_RESET); - } - delay_us(1); - digitalWrite(GPIOx,SCL, Bit_SET); - delay_us(2); - digitalWrite(GPIOx,SCL, Bit_RESET); - // IIC_Byte<<=1; - } - digitalWrite(GPIOx,SDA, Bit_SET); - delay_us(1); - digitalWrite(GPIOx,SCL, Bit_SET); - delay_us(2); - digitalWrite(GPIOx,SCL, Bit_RESET); -} - - -void delay_us(int us) -{ - volatile uint32_t delay = us; // approximate loops per ms at 24 MHz, Debug config + volatile uint32_t delay = us; // approximate loops per ms at 24 MHz, Debug config for(; delay != 0; delay--) __NOP(); } -void delay_ms(int count) { - delay_us(count*1000); +void i2c_loop_ms(int count) { + i2c_loop_us(count*1000); }
--- a/targets/cmsis/TARGET_WIZNET/TARGET_W7500x/W7500x_i2c.h Mon Jun 29 04:14:49 2015 +0000 +++ b/targets/cmsis/TARGET_WIZNET/TARGET_W7500x/W7500x_i2c.h Mon Jun 29 05:49:52 2015 +0000 @@ -193,8 +193,6 @@ int I2C_Burst_Read (I2C_TypeDef* I2Cx, uint16_t address, uint8_t *data, int length, int stop); int I2C_Burst_Write (I2C_TypeDef* I2Cx, uint16_t address, uint8_t *data, int length, int stop); -void I2C_Delay (uint32_t nCount); - void I2C_GenerateSTART (I2C_TypeDef* I2Cx, FunctionalState NewState); void I2C_GenerateSTOP (I2C_TypeDef* I2Cx, FunctionalState NewState); @@ -229,8 +227,8 @@ void digitalWrite(GPIO_TypeDef* GPIOx,uint16_t pin, uint16_t val); uint16_t digitalRead(GPIO_TypeDef* GPIOx,uint16_t pin); -void delay_us(int us); -void delay_ms(int count) ; +void i2c_loop_us(int us); +void i2c_loop_ms(int count) ; /** * @}