i2c working. However, the app crash when accelerometer and gyroscope work together
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Mon, 21 Oct 2013 08:28:44 +0000 (08:28 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Mon, 21 Oct 2013 08:28:44 +0000 (08:28 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@125 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

Makefile
lib/HAL_L3Gx.c
lib/HAL_L3Gx.h
lib/HAL_LSM303DLHC.h
lib/L3Gx/src/L3Gx.dep [deleted file]
lib/Makefile
lib/i2c.c
lib/i2c.h
lib/spi.c
lib/spi.h
multitouchglove.c

index 7a643c9786a01200f8bbaebd62140b6ee5700f53..b128c7c2ebb4f566e6172682e01612a164109ba7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,7 @@ ROOTDIR = $(CURDIR)/uC-sdk
 export BOARD = inemo
 
 TARGET = multitouchglove.bin
-TARGET_OBJS = lib/spi.o lib/uart.o lib/i2c.o lib/HAL_L3Gx.o lib/L3Gx/src/L3Gx.o  lib/LSM303DLHC/src/LSM303DLHC.o
-
-#lib/HAL_LSM303DLHC.o
+TARGET_OBJS = lib/spi.o lib/uart.o lib/i2c.o lib/HAL_L3Gx.o lib/HAL_LSM303DLHC.o lib/L3Gx/src/L3Gx.o  lib/LSM303DLHC/src/LSM303DLHC.o
 
 LIBDEPS = uC-sdk/FreeRTOS/libFreeRTOS.a uC-sdk/arch/libarch.a uC-sdk/os/libos.a uC-sdk/libc/libc.a uC-sdk/libm/libm.a uC-sdk/acorn/libacorn.a
 LIBS = -Wl,--start-group $(LIBDEPS) -Wl,--end-group
@@ -17,14 +15,14 @@ export ROOTDIR = $(MAINDIR)/uC-sdk/
 include $(MAINDIR)/lib/config.mk
 include $(ROOTDIR)/common.mk
 
-all: uC-sdk lib $(TARGET)
+all: deps uC-sdk lib $(TARGET)
 
 clean: clean-generic
        $(Q)rm -f $(TARGET)
        $(Q)$(MAKE) $(MAKE_OPTS) -C uC-sdk clean
        $(Q)$(MAKE) $(MAKE_OPTS) -C lib clean
 
-.PHONY: uC-sdk
+.PHONY: uC-sdk lib
 
 uC-sdk/FreeRTOS/libFreeRTOS.a: uC-sdk
 uC-sdk/arch/libarch.a: uC-sdk
@@ -41,14 +39,11 @@ uC-sdk:
        $(E) "[MAKE]   Entering uC-sdk"
        $(Q)$(MAKE) $(MAKE_OPTS) -C uC-sdk
 
-romfs.o:
-       $(E) "[ROMFS]  Building romfs"
-       $(Q)uC-sdk/tools/mkromfs -d romfs romfs.bin
-       $(Q)$(TARGET_OBJCOPY_BIN) --prefix-sections '.romfs' romfs.bin romfs.o
-
 deps: ldeps
        $(E) "[DEPS]   Creating dependency tree for uC-sdk"
        $(Q)$(MAKE) $(MAKE_OPTS) -C uC-sdk ldeps
+       $(E) "[DEPS]   Creating dependency tree for lib"
+       $(Q)$(MAKE) $(MAKE_OPTS) -C lib ldeps
 
 include $(ROOTDIR)/FreeRTOS/config.mk
 include $(ROOTDIR)/arch/config.mk
index 117ab94df5bd760853d00557b1f326d402557864..1952de82053217ec3457f2d303bdde5ae088d13f 100644 (file)
@@ -3,43 +3,37 @@
 #include "stm32f10x.h"
 #include <stdio.h>
 
-void spi_get(uint8_t *buffer, uint8_t address, uint8_t nb)
+void spi_get(uint8_t address, uint8_t *buffer, uint8_t nb)
 {
-       //set the read bit
+    //set the read bit
     address |= 0xC0;
 
     //reset multiple byte bit if necessary
     if (nb <= 1)
         address &= 0xBF;
-
-       spi_start(2);
-
-       //send the request
+    spi_start(2);
+    //send the request
     spi_write(2, &address, 1);
 
     //get the value
     spi_read(2, buffer, nb);
-
-       spi_stop(2);
+    spi_stop(2);
 }
 
-void spi_set(uint8_t *buffer, uint8_t address, uint8_t nb)
+void spi_set(uint8_t address, uint8_t *buffer, uint8_t nb)
 {
-       //reset the read bit
+    //reset the read bit
     address &= 0x3F;
 
     //set multiple byte bit if necessary
     if (nb > 1)
         address |= 0x40;
-
-       spi_start(2);
-
-       //send the request
+    spi_start(2);
+    //send the request
     spi_write(2, &address, 1);
 
     //send the value
     spi_write(2, buffer, nb);
-
-       spi_stop(2);
+    spi_stop(2);
 }
 
index b6b3dbc63f8ee730ca56b4eb763c28e11166b13d..cceb3628798109ef1a2b5af33d87a0cd2a328a21 100755 (executable)
@@ -8,10 +8,10 @@
 #include "spi.h"\r
 \r
 #define L3gxCommInit()                             spi_init(2)\r
-#define L3gxBufferRead(pVal,cAddress,nBytes)       spi_get(pVal,cAddress,nBytes)\r
-#define L3gxBufferWrite(pVal,cAddress,nBytes)      spi_set(pVal,cAddress,nBytes)\r
+#define L3gxBufferRead(buffer, address, nb)        spi_get(address, buffer, nb)\r
+#define L3gxBufferWrite(buffer, address, nb)       spi_set(address, buffer, nb)\r
 \r
-void spi_get(uint8_t *buffer, uint8_t address, uint8_t nb);\r
-void spi_set(uint8_t *pcBuffer, uint8_t address, uint8_t nb);\r
+void spi_get(uint8_t address, uint8_t *buffer, uint8_t nb);\r
+void spi_set(uint8_t address, uint8_t *buffer, uint8_t nb);\r
 \r
 #endif\r
index a623082bcab0c1332626e58013c0cd54532a1366..80bc74fbdda72e229611e8bc3dcfacac4e298e04 100755 (executable)
@@ -8,20 +8,11 @@
 #include "stm32f10x.h"\r
 #include "i2c.h"\r
 \r
-   \r
-#define LSM_I2C                  I2C2   \r
-#define LSM_I2C_Speed            400000\r
+#define Lsm303dlhcI2CInit()                                      i2c_init(2, LSM_I2C_Speed)\r
+#define Lsm303dlhcI2CBufferRead(dest, buffer, address, nb)       i2c_get(dest, address, buffer, nb)\r
+#define Lsm303dlhcI2CBufferWrite(dest, buffer, address, nb)      i2c_set(dest, address, buffer, nb)\r
 \r
-#define LSM_A_INT1_Pin           GPIO_Pin_2\r
-#define LSM_A_INT1_Port          GPIOD\r
-#define LSM_A_INT1_RCC_Port      RCC_APB2Periph_GPIOD\r
-\r
-#define LSM_A_INT2_Pin           GPIO_Pin_5\r
-#define LSM_A_INT2_Port          GPIOB\r
-#define LSM_A_INT2_RCC_Port      RCC_APB2Periph_GPIOB\r
-          \r
-#define Lsm303dlhcI2CInit()                                             i2c_init(2, LSM_I2C_Speed)\r
-#define Lsm303dlhcI2CBufferRead(cDevAddress,pVal,cAddress,nBytes)       iNemoI2CBufferRead(cDevAddress,pVal,cAddress,nBytes)\r
-#define Lsm303dlhcI2CBufferWrite(cDevAddress,pVal,cAddress,nBytes)      iNemoI2CBufferWrite(cDevAddress,pVal,cAddress,nBytes)\r
+void i2c_get(uint8_t destination, uint8_t address, uint8_t *buffer, uint8_t nb);\r
+void i2c_set(uint8_t destination, uint8_t address, uint8_t *pcBuffer, uint8_t nb);\r
 \r
 #endif\r
diff --git a/lib/L3Gx/src/L3Gx.dep b/lib/L3Gx/src/L3Gx.dep
deleted file mode 100644 (file)
index a05f898..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-L3Gx/src/L3Gx.o: L3Gx/src/L3Gx.c \
- /Users/tom/Documents/src/multitouchglove/lib/L3Gx/inc/L3Gx.h \
- /usr/local/bin/../lib/gcc/arm-none-eabi/4.7.4/include/stdint.h \
- /usr/local/bin/../lib/gcc/arm-none-eabi/4.7.4/include/stdint-gcc.h \
- /Users/tom/Documents/src/multitouchglove/lib/HAL_L3Gx.h \
- /Users/tom/Documents/src/multitouchglove/lib/spi.h \
- /Users/tom/Documents/src/multitouchglove/uC-sdk/arch/arm/stm32f10x/Core/CM3/DeviceSupport/ST/STM32F10x/stm32f10x.h \
- /Users/tom/Documents/src/multitouchglove/uC-sdk/arch/arm/src/CM3/CoreSupport/core_cm3.h \
- /Users/tom/Documents/src/multitouchglove/uC-sdk/arch/arm/stm32f10x/Core/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.h \
- /Users/tom/Documents/src/multitouchglove/uC-sdk/config/arm/stm32f10/stm32f10x_conf.h \
- /Users/tom/Documents/src/multitouchglove/uC-sdk/arch/arm/stm32f10x/inemo/BoardConsole.h \
- /usr/local/bin/../lib/gcc/arm-none-eabi/4.7.4/include/stdarg.h
index 8f07f079b2fdd3294959d2e4b668abbad6885ea6..97e330c992f9cc1019e53533686865872b8e910a 100644 (file)
@@ -1,6 +1,6 @@
 #TARGET_LIB = libinemo.a
 
-all:
+all:  $(TARGET_OBJ)
 # $(TARGET_LIB)
 
 export BOARD = inemo
@@ -15,6 +15,7 @@ TARGET_SRCS += uart.c
 TARGET_SRCS += spi.c
 TARGET_SRCS += i2c.c
 TARGET_SRCS += HAL_L3Gx.c
+TARGET_SRCS += HAL_LSM303DLHC.c
 #TARGET_SRCS += i2c.c
 #TARGET_SRCS = iNEMO_Compass/src/iNEMO_Compass.c
 #TARGET_SRCS += iNEMO_M1_SensorDrivers/src/iNEMO_I2C_Driver.c
index 6dcb8cdfb1123879132f2248a536c0f54bf8644b..c72f126d457165c48a18eb8f2e44f9131654fadc 100644 (file)
--- a/lib/i2c.c
+++ b/lib/i2c.c
@@ -7,20 +7,6 @@
 
 #include <stdio.h>
 
-#define FORCE_CRITICAL_SEC
-
-#define I2C1_DR_Address               0x40005410
-#define I2C2_DR_Address               0x40005810
-
-#define I2C1_DMA_CHANNEL_TX           DMA1_Channel6
-#define I2C1_DMA_CHANNEL_RX           DMA1_Channel7
-#define I2C2_DMA_CHANNEL_TX           DMA1_Channel4
-#define I2C2_DMA_CHANNEL_RX           DMA1_Channel5
-
-#define I2C_DIRECTION_TX 0
-#define I2C_DIRECTION_RX 1
-
-#define DMA_BUFFER_SIZE       196
 
 struct i2cInitDef_t {
     // scl / sda
@@ -44,11 +30,6 @@ static struct i2cInitDef_t i2cInitDefs[2] = {
 };
 
 
-
-
-
-
-
 void i2c_init(uint8_t id, uint32_t speed)
 {
     if (!((id >= 1) && (id <= 3)))
@@ -88,400 +69,86 @@ void i2c_dma_init(uint8_t id)
 
 }
 
-void uart_read_polling(uint8_t id, uint8_t *buffer, uint8_t nb)
+void i2c_start_read(uint8_t id, uint8_t destination)
 {
+    if (!((id >= 1) && (id <= 3)))
+        return;
 
-}
-
-void uart_write_polling(uint8_t id, uint8_t *buffer, uint8_t nb)
-{
+    struct i2cInitDef_t * i2cInitDef = i2cInitDefs + id - 1;
 
+         I2C_GenerateSTART(i2cInitDef->id, ENABLE);
+    while(!I2C_CheckEvent(i2cInitDef->id, I2C_EVENT_MASTER_MODE_SELECT));
+    I2C_Send7bitAddress(i2cInitDef->id, destination, I2C_Direction_Receiver);
+    while(!I2C_CheckEvent(i2cInitDef->id, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
 }
 
-void uart_read_dma(uint8_t id, uint8_t *buffer, uint8_t nb)
+void i2c_start_write(uint8_t id, uint8_t destination)
 {
+    if (!((id >= 1) && (id <= 3)))
+        return;
 
-}
-
-void uart_write_dma(uint8_t id, uint8_t *buffer, uint8_t nb)
-{
+    struct i2cInitDef_t * i2cInitDef = i2cInitDefs + id - 1;
 
+    I2C_GenerateSTART(i2cInitDef->id, ENABLE);
+    while(!I2C_CheckEvent(i2cInitDef->id, I2C_EVENT_MASTER_MODE_SELECT));
+    I2C_Send7bitAddress(i2cInitDef->id, destination, I2C_Direction_Transmitter);
+    while(!I2C_CheckEvent(i2cInitDef->id, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
 }
 
+void i2c_stop(uint8_t id)
+{
+    if (!((id >= 1) && (id <= 3)))
+        return;
 
+    struct i2cInitDef_t * i2cInitDef = i2cInitDefs + id - 1;
 
-
-#if 0
+    I2C_GenerateSTOP(i2cInitDef->id, ENABLE);
+}
 
 
-/**
- * @brief  Reads a block of data from the device by DMA.
- * @brief  I2C2: I2C peripherial to use.
- * @param  cAddr: slave address.
- * @param  pcBuffer: pointer to the buffer that receives the data read.
- * @param  cReadAddr: register internal address to read from.
- * @param  nNumByteToRead: number of bytes to read.
- * @retval None
- */
-void iNemoI2CBufferReadDma(uint8_t cAddr, uint8_t* pcBuffer, uint8_t cReadAddr, uint8_t cNumByteToRead)
+void i2c_read_polling(uint8_t id, uint8_t *buffer, uint8_t nb)
 {
-  
-    __IO uint32_t temp = 0;
-    __IO uint32_t Timeout = 0;
-    
-    /* Enable I2C errors interrupts */
-    I2C2->CR2 |= I2C_IT_ERR;
-    
-    /* Set the MSb of the register address in case of multiple readings */
-    if(cNumByteToRead>1)
-      cReadAddr |= 0x80;
-    
-#ifdef FORCE_CRITICAL_SEC
-    __disable_irq();
-#endif    
-    
-    /* While the bus is busy */
-    while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY));
-    
-    /* Send START condition */
-    I2C_GenerateSTART(I2C2, ENABLE);
-    
-    /* Test on EV5 and clear it */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
-    
-    /* Send LSM303DLH address for read */
-    I2C_Send7bitAddress(I2C2, cAddr, I2C_Direction_Transmitter);
-    
-    /* Test on EV6 and clear it */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
-    
-    /* Clear EV6 by setting again the PE bit */
-    I2C_Cmd(I2C2, ENABLE);
-    
-    /* Send the LSM303DLH_Magn's internal address to write to */
-    I2C_SendData(I2C2, cReadAddr);
-    
-    /* Test on EV8 and clear it */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
-    
-    /* Configure I2C2 DMA channel */
-    iNemoI2CDMAConfig(I2C2, pcBuffer, cNumByteToRead, I2C_DIRECTION_RX);
-    
-    /* Set Last bit to have a NACK on the last received byte */
-    I2C2->CR2 |= 0x1000;
-    
-    /* Enable I2C DMA requests */
-    I2C_DMACmd(I2C2, ENABLE);
-    Timeout = 0xFFFF;
-    
-    /* Send START condition */
-    I2C_GenerateSTART(I2C2, ENABLE);
-    
-    /* Wait until SB flag is set: EV5  */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT))
-    {
-      if (Timeout-- == 0)
-        return;
-    }
-    Timeout = 0xFFFF;
-    
-    /* Send LSM303DLH address for read */
-    I2C_Send7bitAddress(I2C2, cAddr, I2C_Direction_Receiver);
-    
-    /* Wait until ADDR is set: EV6 */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
-    {
-      if (Timeout-- == 0)
+    if (!((id >= 1) && (id <= 3)))
         return;
-    }
-    /* Clear ADDR flag by reading SR2 register */
-    temp = I2C2->SR2;
-    
-    
-    
-    if(I2C2 == I2C2)
-    {
-      /* Wait until DMA end of transfer */
-      while (!DMA_GetFlagStatus(DMA1_FLAG_TC5));
-      /* Disable DMA Channel */
-      DMA_Cmd(I2C2_DMA_CHANNEL_RX, DISABLE);
-      
-      /* Clear the DMA Transfer Complete flag */
-      DMA_ClearFlag(DMA1_FLAG_TC5);
-    }
-    else
+
+    struct i2cInitDef_t * i2cInitDef = i2cInitDefs + id - 1;
+    while(nb--)
     {
-      /* Wait until DMA end of transfer */
-      while (!DMA_GetFlagStatus(DMA1_FLAG_TC7));
-      /* Disable DMA Channel */
-      DMA_Cmd(I2C1_DMA_CHANNEL_RX, DISABLE);
+        if(nb == 0)
+            I2C_AcknowledgeConfig(i2cInitDef->id, DISABLE);
       
-      /* Clear the DMA Transfer Complete flag */
-      DMA_ClearFlag(DMA1_FLAG_TC7);
+      while(!I2C_CheckEvent(i2cInitDef->id, I2C_EVENT_MASTER_BYTE_RECEIVED));
+      *buffer++ = I2C_ReceiveData(i2cInitDef->id);
     }
     
-       
-    /* Disable Ack for the last byte */
-    I2C_AcknowledgeConfig(I2C2, DISABLE);
-    
-    /* Send STOP Condition */
-    I2C_GenerateSTOP(I2C2, ENABLE);
-    
-    /* Make sure that the STOP bit is cleared by Hardware before CR1 write access */
-    while ((I2C2->CR1 & 0x0200) == 0x0200);
-    
-    /* Enable Acknowledgement to be ready for another reception */
-    I2C_AcknowledgeConfig(I2C2, ENABLE);
-    
-#ifdef FORCE_CRITICAL_SEC
-    __enable_irq();
-#endif
-    
+    I2C_AcknowledgeConfig(i2cInitDef->id, ENABLE);
 }
-#endif
-
-/**
- * @brief  Reads a block of data from the device by polling.
- * @brief  I2C2: I2C peripherial to use.
- * @param  cAddr: slave address.
- * @param  pcBuffer: pointer to the buffer that receives the data read.
- * @param  cReadAddr: register internal address to read from.
- * @param  nNumByteToRead: number of bytes to read.
- * @retval None
- */
-void iNemoI2CBufferRead(uint8_t cAddr, uint8_t* pcBuffer, uint8_t cReadAddr, uint8_t cNumByteToRead)
+
+void i2c_write_polling(uint8_t id, uint8_t *buffer, uint8_t nb)
 {
-    /* Set the MSb of the register address in case of multiple readings */
-    if(cNumByteToRead>1)
-      cReadAddr |= 0x80;
-    
-#ifdef FORCE_CRITICAL_SEC
-    __disable_irq();
-#endif
-    
-    /* While the bus is busy */
-    while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY));
-    
-    /* Send START condition */
-    I2C_GenerateSTART(I2C2, ENABLE);
-    
-    /* Test on EV5 and clear it */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
-    
-    /* Send LSM303DLH address for write */
-    I2C_Send7bitAddress(I2C2, cAddr, I2C_Direction_Transmitter);
-    
-    /* Test on EV6 and clear it */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
-    
-    /* Clear EV6 by setting again the PE bit */
-    I2C_Cmd(I2C2, ENABLE);
-    
-    /* Send the LSM303DLH_Magn's internal address to write to */
-    I2C_SendData(I2C2, cReadAddr);
-    
-    /* Test on EV8 and clear it */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
-    
-    /* Send START condition a second time */
-    I2C_GenerateSTART(I2C2, ENABLE);
-    
-    /* Test on EV5 and clear it */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
-    
-    /* Send LSM303DLH address for read */
-    I2C_Send7bitAddress(I2C2, cAddr, I2C_Direction_Receiver);
-    
-    /* Test on EV6 and clear it */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
-    
-    /* While there is data to be read */
-    while(cNumByteToRead)
+    if (!((id >= 1) && (id <= 3)))
+        return;
+
+    struct i2cInitDef_t * i2cInitDef = i2cInitDefs + id - 1;
+
+    taskENTER_CRITICAL();
+
+    while (nb--)
     {
-      if(cNumByteToRead == 1)
-      {
-        /* Disable Acknowledgement */
-        I2C_AcknowledgeConfig(I2C2, DISABLE);
-        
-        /* Send STOP Condition */
-        I2C_GenerateSTOP(I2C2, ENABLE);
-      }
-      
-      /* Test on EV7 and clear it */
-      if(I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED))
-      {
-        /* Read a byte from the LSM303DLH */
-        *pcBuffer = I2C_ReceiveData(I2C2);
-        
-        /* Point to the next location where the byte read will be saved */
-        pcBuffer++;
-        
-        /* Decrement the read bytes counter */
-        cNumByteToRead--;
-      }
+        I2C_SendData(i2cInitDef->id, *buffer++);
+        while(!I2C_CheckEvent(i2cInitDef->id, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
     }
-    
-    /* Enable Acknowledgement to be ready for another reception */
-    I2C_AcknowledgeConfig(I2C2, ENABLE);
-    
-#ifdef FORCE_CRITICAL_SEC
-    __enable_irq();
-#endif
-  
+    taskEXIT_CRITICAL();
 }
-      
-#if 0
-/**
- * @brief  Writes a block of data to the device by DMA.
- * @brief  I2C2: I2C peripherial to use.
- * @param  cAddr : slave address.
- * @param  pcBuffer : pointer to the buffer  containing the data to be written.
- * @param  cWriteAddr : register internal address to write to.
- * @param  nNumByteToWrite : number of bytes to write.
- * @retval None
- */
-void iNemoI2CBufferWriteDma(uint8_t cAddr, uint8_t* pcBuffer, uint8_t cWriteAddr, uint8_t cNumByteToWrite)
+
+void i2c_read_dma(uint8_t id, uint8_t *buffer, uint8_t nb)
 {
-    
-  __IO uint32_t temp = 0;
-  __IO uint32_t Timeout = 0;
-  
-  static uint8_t pcDmaBuffer[DMA_BUFFER_SIZE+1];
-  
-  /* Set to 1 the MSb of the register address in case of multiple byte writing */
-  if(cNumByteToWrite>1)
-    cWriteAddr |= 0x80;
-  
-  pcDmaBuffer[0]=cWriteAddr;
-  memcpy(&pcDmaBuffer[1],pcBuffer,cNumByteToWrite);
-  
-  /* Enable Error IT  */
-  I2C2->CR2 |= I2C_IT_ERR;
-  
-  Timeout = 0xFFFF;
-  /* Configure the DMA channel for I2C2 transmission */
-  iNemoI2CDMAConfig(I2C2, pcDmaBuffer, cNumByteToWrite+1, I2C_DIRECTION_TX);
-  
-  /* Enable DMA for I2C */
-  I2C_DMACmd(I2C2, ENABLE);
-   
-  /* Send START condition */
-  I2C_GenerateSTART(I2C2, ENABLE);
-  
-  
-  /* Wait until SB flag is set: EV5 */
-  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT))
-  {
-    if (Timeout-- == 0)
-      return;
-  }
-  
-  Timeout = 0xFFFF;
-  
-  /* Send LSM303DLH address for write */
-  I2C_Send7bitAddress(I2C2, cAddr, I2C_Direction_Transmitter);
-  
-  /* Wait until ADDR is set: EV6 */
-  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
-  {
-    if (Timeout-- == 0)
-      return;
-  }
-  
-  /* Clear ADDR flag by reading SR2 register */
-  temp = I2C2->SR2;
-  
-  
-  /* Disable the DMA1 channel */
-  if(I2C2 == I2C2)
-  {
-    /* Wait until DMA end of transfer */
-    while (!DMA_GetFlagStatus(DMA1_FLAG_TC4));
-    /* Disable DMA Channel */
-    DMA_Cmd(I2C2_DMA_CHANNEL_TX, DISABLE);
-    
-    /* Clear the DMA Transfer complete flag */
-    DMA_ClearFlag(DMA1_FLAG_TC4);
-  }
-  else
-  {
-    /* Wait until DMA end of transfer */
-    while (!DMA_GetFlagStatus(DMA1_FLAG_TC6));
-    /* Disable DMA Channel */
-    DMA_Cmd(I2C1_DMA_CHANNEL_TX, DISABLE);
-    
-    /* Clear the DMA Transfer complete flag */
-    DMA_ClearFlag(DMA1_FLAG_TC6);
-  }
-  
-  /* EV8_2: Wait until BTF is set before programming the STOP */
-  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
-   
-  /* Send STOP Condition */
-  I2C_GenerateSTOP(I2C2, ENABLE);
-  
-  /* Make sure that the STOP bit is cleared by Hardware before CR1 write access */
-  while ((I2C2->CR1 & 0x0200) == 0x0200);
-  
+
 }
-#endif
-
-/**
- * @brief  Writes a block of data to the device by polling.
- * @brief  I2C2: I2C peripherial to use.
- * @param  cAddr : slave address.
- * @param  pcBuffer : pointer to the buffer  containing the data to be written.
- * @param  cWriteAddr : register internal address to write to.
- * @param  nNumByteToWrite : number of bytes to write.
- * @retval None
- */
-void iNemoI2CBufferWrite(uint8_t cAddr, uint8_t* pcBuffer, uint8_t cWriteAddr, uint8_t cNumByteToWrite)
-{   
-    /* Set to 1 the MSb of the register address in case of multiple byte writing */
-    if(cNumByteToWrite>1)
-      cWriteAddr |= 0x80;
-    
-#ifdef FORCE_CRITICAL_SEC
-    __disable_irq();
-#endif
-    
-    /* While the bus is busy */
-    while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY));
-    
-    /* Send START condition */
-    I2C_GenerateSTART(I2C2, ENABLE);
-    
-    /* Test on EV5 and clear it */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
-    
-    /* Send LSM303DLH address for write */
-    I2C_Send7bitAddress(I2C2, cAddr, I2C_Direction_Transmitter);
-    
-    /* Test on EV6 and clear it */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
-    
-    /* Send the LSM303DLHC_internal register address to write */
-    I2C_SendData(I2C2, cWriteAddr);
-    
-    /* Test on EV8 and clear it */
-    while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
-    
-    uint8_t i;
-    for(i=0 ; i<cNumByteToWrite ; i++)
-    {
-      /* Send the byte to be written */
-      I2C_SendData(I2C2, pcBuffer[i]);
-      
-      /* Test on EV8 and clear it */
-      while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
-    }
-    
-    /* Send STOP condition */
-    I2C_GenerateSTOP(I2C2, ENABLE);
-    
-#ifdef FORCE_CRITICAL_SEC
-    __enable_irq();
-#endif
-  
+
+void i2c_write_dma(uint8_t id, uint8_t *buffer, uint8_t nb)
+{
+
 }
+
index efdf234cd5f7d89dd449375b8fba1a81ed402e2c..212e0c002892c976d323ee89df118d3ddbc07bc1 100644 (file)
--- a/lib/i2c.h
+++ b/lib/i2c.h
@@ -6,15 +6,17 @@
 void i2c_init(uint8_t id, uint32_t speed);
 void i2c_dma_init(uint8_t id);
 
-void uart_read_polling(uint8_t id, uint8_t *buffer, uint8_t nb);
-void uart_write_polling(uint8_t id, uint8_t *buffer, uint8_t nb);
+//call before initiating a read communication
+void i2c_start_read(uint8_t id, uint8_t destination);
+//call before initiating a write communication
+void i2c_start_write(uint8_t id, uint8_t destination);
+//call after communication ended
+void i2c_stop(uint8_t id);
 
-void uart_read_dma(uint8_t id, uint8_t *buffer, uint8_t nb);
-void uart_write_dma(uint8_t id, uint8_t *buffer, uint8_t nb);
+void i2c_read_polling(uint8_t id, uint8_t *buffer, uint8_t nb);
+void i2c_write_polling(uint8_t id, uint8_t *buffer, uint8_t nb);
 
-//void iNemoI2CBufferReadDma(uint8_t cAddr, uint8_t* pcBuffer, uint8_t cReadAddr, uint8_t cNumByteToRead);
-void iNemoI2CBufferRead(uint8_t cAddr, uint8_t* pcBuffer, uint8_t cReadAddr, uint8_t cNumByteToRead);
-//void iNemoI2CBufferWriteDma(uint8_t cAddr, uint8_t* pcBuffer, uint8_t cWriteAddr, uint8_t cNumByteToWrite);
-void iNemoI2CBufferWrite(uint8_t cAddr, uint8_t* pcBuffer, uint8_t cWriteAddr, uint8_t cNumByteToWrite);
+void i2c_read_dma(uint8_t id, uint8_t *buffer, uint8_t nb);
+void i2c_write_dma(uint8_t id, uint8_t *buffer, uint8_t nb);
 
 #endif
\ No newline at end of file
index e74e7ce4430243435413280b01d08839b24e77a7..44bd6a11077c86ef16d8367ac58a130ad86da622 100644 (file)
--- a/lib/spi.c
+++ b/lib/spi.c
@@ -110,7 +110,6 @@ void spi_read(uint8_t id, uint8_t *buffer, uint8_t nb)
         //read data
         while (SPI_I2S_GetFlagStatus(spiInitDef->id, SPI_I2S_FLAG_RXNE) == RESET);
         *buffer++ = (uint8_t) SPI_I2S_ReceiveData(spiInitDef->id);
-        //printf("%02x", *buffer);
 
         taskEXIT_CRITICAL();
     }
index 58ff45098f3b791589ec94c97b41fe9d3d7fe747..ec05e594c237d0b25b4d2f7de05a766bf32bc77a 100644 (file)
--- a/lib/spi.h
+++ b/lib/spi.h
@@ -14,6 +14,6 @@ void spi_stop(uint8_t id);
 //read data from SPI
 void spi_read(uint8_t id, uint8_t *buffer, uint8_t nb);
 //write data to SPI
-void spi_write(uint8_t id, uint8_t *address, uint8_t nb);
+void spi_write(uint8_t id, uint8_t *buffer, uint8_t nb);
 
 #endif
index 7a6c34ebd3d0b762072bf17c07a59c69904768c8..fbf35d2e7b4b970738875c89e17e73b01d34147b 100644 (file)
@@ -15,7 +15,7 @@
 #include <LSM303DLHC.h>
 
 #define LEDS
-#define GYRO
+//#define GYRO
 #define ACCELERO
 
 #ifdef LEDS
@@ -72,16 +72,16 @@ void initGyro()
 
 void getGyroInfo()
 {
-    L3GInit L3GInitStructure;
+    L3GInit gyroinfo;
 
-    L3gd20GetInfo(&L3GInitStructure);
+    L3gd20GetInfo(&gyroinfo);
 
-    printf("Power mode: %02x\n", L3GInitStructure.xPowerMode);
-    printf("Output data rate: %02x\n", L3GInitStructure.xOutputDataRate);
-    printf("Enabled axes: %02x\n", L3GInitStructure.xEnabledAxes);
-    printf("Full scale: %02x\n", L3GInitStructure.xFullScale);
-    printf("Data update: %02x\n", L3GInitStructure.xDataUpdate);
-    printf("Endianness: %02x\n", L3GInitStructure.xEndianness);
+    printf("Power mode: %02x\n", gyroinfo.xPowerMode);
+    printf("Output data rate: %02x\n", gyroinfo.xOutputDataRate);
+    printf("Enabled axes: %02x\n", gyroinfo.xEnabledAxes);
+    printf("Full scale: %02x\n", gyroinfo.xFullScale);
+    printf("Data update: %02x\n", gyroinfo.xDataUpdate);
+    printf("Endianness: %02x\n", gyroinfo.xEndianness);
 }
 
 static void gyroTask(void *p) 
@@ -118,6 +118,21 @@ void initAccelero()
     Lsm303dlhcAccConfig(&accelerodef);
 }
 
+void getAcceleroInfo()
+{
+    LSMAccInit acceleroinfo;
+
+    Lsm303dlhcAccGetInfo(&acceleroinfo);
+
+    printf("Power mode: %02x\n", acceleroinfo.xPowerMode);
+    printf("Output data rate: %02x\n", acceleroinfo.xOutputDataRate);
+    printf("Enabled axes: %02x\n", acceleroinfo.xEnabledAxes);
+    printf("Full scale: %02x\n", acceleroinfo.xFullScale);
+    printf("Data update: %02x\n", acceleroinfo.xDataUpdate);
+    printf("Endianness: %02x\n", acceleroinfo.xEndianness);
+    printf("High Resolution: %02x\n", acceleroinfo.xHighResolution);
+}
+
 static void acceleroTask(void *p) 
 {
     printf("Start accelero task\n");
@@ -147,18 +162,21 @@ int main()
 #endif
 
 #ifdef GYRO
-    printf("Init SPI 2\n");
+    printf("Init SPI2\n");
     spi_init(2);
-    getGyroInfo();
     printf("Init Gyro\n");
     initGyro();
+    printf("Get Gyro Information\n");
+    getGyroInfo();
     printf("Start gyroTask\n");
     xTaskCreate(gyroTask, (const signed char *)NULL, configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY, NULL);
 #endif
 
 #ifdef ACCELERO
-    printf("Init I2C2 2\n");
+    printf("Init I2C2\n");
     i2c_init(2, 400000);
+    printf("Get Accelero Information\n");
+    getAcceleroInfo();
     printf("Init Accelero\n");
     initAccelero();
     printf("Start acceleroTask\n");