From 4983f340feb7152828cae2d2d746f59f0a7cbb79 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Tue, 1 Apr 2014 07:48:58 +0000 Subject: [PATCH] I2C Compiled and ready to test --- Project/applications/smartcities/Makefile | 2 +- Project/applications/smartcities/i2c.c | 16 +++++----------- Project/applications/smartcities/include/i2c.h | 6 +++++- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Project/applications/smartcities/Makefile b/Project/applications/smartcities/Makefile index ea03010..c24479f 100644 --- a/Project/applications/smartcities/Makefile +++ b/Project/applications/smartcities/Makefile @@ -10,7 +10,7 @@ SDK_ROOT = ../../ PROJECT_OUT = smartcities -USER_SRC = main.c httpClient.c callbacks.c module.c sensors.c json.c +USER_SRC = main.c httpClient.c callbacks.c module.c sensors.c json.c i2c.c USER_INCDIR = include/ # if you need to add build Defines options add to USER_DEFS define diff --git a/Project/applications/smartcities/i2c.c b/Project/applications/smartcities/i2c.c index 86521f9..730fc72 100644 --- a/Project/applications/smartcities/i2c.c +++ b/Project/applications/smartcities/i2c.c @@ -1,24 +1,22 @@ -#include -#include +#include "i2c.h" -void I2C1_init() +void I2C_init(void) { GPIO_InitTypeDef GPIO_InitStruct; I2C_InitTypeDef I2C_InitStruct; RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); /* * 1. SCL on PB6 or PB8 * 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_Mode = GPIO_Mode_A + GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStruct.GPIO_OType = GPIO_OType_OD; // set output to open drain - GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; // enable pull up resistors GPIO_Init(GPIOB, &GPIO_InitStruct); // init GPIOB /* WARNING @@ -28,10 +26,6 @@ void I2C1_init() * --Imanol */ - // Connect I2C1 pins to AF - GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1); // SCL - GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_I2C1); // SDA - // configure I2C1 I2C_InitStruct.I2C_ClockSpeed = 100000; // 100kHz - STANDARD MODE I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; diff --git a/Project/applications/smartcities/include/i2c.h b/Project/applications/smartcities/include/i2c.h index b214b7c..130c837 100644 --- a/Project/applications/smartcities/include/i2c.h +++ b/Project/applications/smartcities/include/i2c.h @@ -1,7 +1,11 @@ #ifndef I2C_H #define I2C_H -void I2C1_init(); +#include "stm32f10x.h" +#include "stm32f10x_i2c.h" +#include "stm32f10x_gpio.h" + +void I2C_init(void); void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction); void I2C_stop(I2C_TypeDef* I2Cx); void I2C_write(I2C_TypeDef* I2Cx, uint8_t data); -- libgit2 0.22.2