diff --git a/Project/applications/smartcities/i2c.c b/Project/applications/smartcities/i2c.c index 730fc72..078cb59 100644 --- a/Project/applications/smartcities/i2c.c +++ b/Project/applications/smartcities/i2c.c @@ -1,4 +1,5 @@ #include "i2c.h" +#include "libwismart.h" void I2C_init(void) { @@ -13,8 +14,7 @@ void I2C_init(void) * 2. SDA on PB7 or PB9 */ - GPIO_PinRemapConfig(GPIO_Remap_I2C1,ENABLE); - GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9; + GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStruct); // init GPIOB @@ -44,13 +44,11 @@ void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) // wait until I2C1 is not busy any more } I2C_GenerateSTART(I2Cx, ENABLE); - while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT)) { // wait for I2C1 EV5 --> Slave has acknowledged start condition } I2C_Send7bitAddress(I2Cx, address, direction); - if(direction == I2C_Direction_Transmitter) { while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) @@ -112,19 +110,43 @@ void I2C_stop(I2C_TypeDef* I2Cx) } } -/* SAMPLE CODE +/* SAMPLE CODE BMP-085 * - * int main(void) - * { - * uint8_t received_data; - * I2C1_init(); // initialize I2C peripheral - * I2C_start(I2C1, SLAVE_ADDRESS<<1, I2C_Direction_Transmitter); // start a transmission in Master transmitter mode - * I2C_write(I2C1, 0x01); // write one byte to the slave - * I2C_stop(I2C1); // stop the transmission - * I2C_start(I2C1, SLAVE_ADDRESS<<1, I2C_Direction_Receiver); // start a transmission in Master receiver mode - * received_data = I2C_read_nack(I2C1); // read one byte and don't request another byte, stop transmission - * while(1); - * return 0; - * } + uint16_t received_data; + char answer[10]; + int32_t UT, X1, X2, B5; // following ds convention + float t; + bmp085_calib_data _bmp085_coeffs; + + printf("Hello\r\n"); + I2C_init(); + + printf("I2C Initialized\r\n"); + I2C_start(I2C1,SLAVE_ADDRESS << 1, I2C_Direction_Transmitter); + printf("I2C First write\r\n"); + I2C_write(I2C1, 0xF4); + printf("I2C Second write\r\n"); + I2C_write(I2C1, 0x2E); + printf("I2C stop\r\n"); + I2C_stop(I2C1); + printf("I2C Temperature measurment started\r\n"); + + I2C_start(I2C1,SLAVE_ADDRESS << 1, I2C_Direction_Transmitter); + printf("I2C First write\r\n"); + I2C_write(I2C1, 0xF6); + printf("I2C stop\r\n"); + I2C_stop(I2C1); + printf("I2C Temperature measurment request sent\r\n"); + + I2C_start(I2C1, SLAVE_ADDRESS<<1, I2C_Direction_Receiver); + printf("I2C Read request sent\r\n"); + received_data = I2C_read_ack(I2C1); + received_data = received_data << 8; + received_data = received_data | I2C_read_ack(I2C1); + printf("I2C data received\r\n"); + + sprintf(answer,"%d",received_data); + printf("Data: %s\r\n",answer); + * --Imanol */