cancel
Showing results for 
Search instead for 
Did you mean: 

Mems on stm3210C eval

eos
Associate II
Posted on September 28, 2010 at 14:09

Mems on stm3210C eval

7 REPLIES 7
xacc
Associate II
Posted on May 17, 2011 at 14:09

You can start with

http://www.st.com/stonline/products/literature/ds/12726/lis302dl.htm

if you have not done so.

tony23
Associate
Posted on May 17, 2011 at 14:09

There is working mems driver code in the eval board firmware:

http://www.st.com/stonline/products/support/micro/files/stm3210c-eval_fw.zip

eos
Associate II
Posted on May 17, 2011 at 14:09

Thanks for the answer. I've read all theses docs; But it is not really helping. I'd rather have some C code to understand how I2C works with the IO Expander (which is where i'm stuck and what I wish to understand). The better would be a very basic example using ST libs.

Best Regards,

eos
Associate II
Posted on May 17, 2011 at 14:09

Hello,

thanks Tonyf, I've also seen this code but it just configure the interupt pin. It doesn't seem to demonstrate how to get datas thought I2C. Besides, when I run this demo, no action seems related to the MEMS.

Also, in the code, the configuration is done thought IOE_2_ADDR and, according to my readings, it is IOE_1_ADDR.

IOE_IOPinConfig(IOE_2_ADDR, (uint32_t)(MEMS_INT1_PIN | MEMS_INT2_PIN), Direction_IN);
 /* ENABLE the alternate function for the Joystick pins */ IOE_IOAFConfig(IOE_2_ADDR, (uint32_t)(MEMS_INT1_PIN | MEMS_INT2_PIN), ENABLE); /* Configure the IOs to detect Falling and Rising Edges */ IOE_IOEdgeConfig(IOE_2_ADDR, (uint32_t)(MEMS_INT1_PIN | MEMS_INT2_PIN), (uint32_t)(EDGE_FALLING | EDGE_RISING)); 

eos
Associate II
Posted on May 17, 2011 at 14:09

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6Wn&d=%2Fa%2F0X0000000bq0%2FQEWNOxFnTxma.nIcnIa0N7nWoWbXZd8odp8LmNXVeeM&asPdf=false
tony23
Associate
Posted on May 17, 2011 at 14:09

The IOE_Config() function configures the peripherals, this should be calledbefore calling other IOE... functions. Have a look through the code for this function for interrupt and I2C initialisation.

For reference, the code below works on my STM3210C, this is based on the example code.

 /**
 * @brief Main program.
 * @param None
 * @retval None
 */
 int main(void)
 {
 uint8_t memsData;
 char lcdLine[20];
 uint32_t revid, devid;
 uint16_t lpCnt; /* Setup the microcontroller system. Initialize the Embedded Flash Interface,
 initialize the PLL and update the SystemFrequency variable. */
 SystemInit(); 
 
 /* SysTick end of count event each 10ms with input clock equal to 9 MHz (HCLK/8, default) */
 SysTick_Config(SystemFrequency / 100);
 
 /* Init Debug Trace functions */
 #ifdef DEBUG_TRACE_ENABLED
 initDefaultDebugTrace();
 printf(''Sys Start OK
'');
 #endif /* Initialize LEDs and push-buttons mounted on STM3210X-EVAL board */
 STM_EVAL_LEDInit(LED1);
 STM_EVAL_LEDInit(LED2);
 STM_EVAL_LEDInit(LED3);
 STM_EVAL_LEDInit(LED4);
 
 STM_EVAL_PBInit(Button_WAKEUP, BUTTON_MODE);
 STM_EVAL_PBInit(Button_TAMPER, BUTTON_MODE);
 STM_EVAL_PBInit(Button_KEY, BUTTON_MODE);
 
 /* Initialize the LCD */
 STM3210C_LCD_Init();
 
 /* Clear the LCD */ 
 LCD_Clear(Blue);
 /* Set the LCD Back Color */
 LCD_SetBackColor(Blue);
 /* Set the LCD Text Color */
 LCD_SetTextColor(White); 
 
 /* Configure the IO Expander */
 if (IOE_Config() == IOE_OK)
 {
 LCD_DisplayStringLine(Line0, ''IO Expander OK'');
 }
 else
 {
 LCD_DisplayStringLine(Line0, ''IO Expander FAIL'');
 LCD_DisplayStringLine(Line1, ''Please Restart board'');
 while(1);
 } /* Configure MEMS */
 memsData = I2C_ReadDeviceRegister(MEMS_I2C_ADDR, MEMS_Who_Am_I);
 if (memsData == MEMS_DEVICE_ID)
 {
 LCD_DisplayStringLine(Line1, ''MEMS comms OK'');
 }
 else
 {
 LCD_DisplayStringLine(Line1, ''MEMS comms FAIL'');
 LCD_DisplayStringLine(Line2, ''Please Restart board'');
 while(1);
 }
 
 /* Power up MEMS */
 if (I2C_WriteDeviceRegister(MEMS_I2C_ADDR, MEMS_Ctrl_Reg1, 0x47) == IOE_OK)
 {
 LCD_DisplayStringLine(Line2, ''MEMS powerup OK'');
 }
 else
 {
 LCD_DisplayStringLine(Line2, ''MEMS powerup FAIL'');
 LCD_DisplayStringLine(Line3, ''Please Restart board'');
 while(1);
 } revid = DBGMCU_GetREVID();
 devid = DBGMCU_GetDEVID();
 sprintf(lcdLine, ''Rev %d Dev %d '', revid, devid);
 LCD_DisplayStringLine(Line9, (uint8_t*)lcdLine); /* Set the LCD Text Color */
 LCD_SetTextColor(Cyan); /* Draw graph borders */
 LCD_DrawRect(120, 120, 18, 120);
 LCD_DrawRect(144, 120, 18, 120);
 LCD_DrawRect(168, 120, 18, 120);
 LCD_DrawLine(139, 60, 5, Vertical);
 LCD_DrawLine(163, 60, 5, Vertical); LCD_DisplayStringLine(Line4, ''64=1G +/-2G''); /* Set the LCD Text Color */
 LCD_SetTextColor(Green); #ifdef DEBUG_TRACE_ENABLED
 printf(''LCD & MEMS initialised OK
'');
 #endif lpCnt = 0; /* Main Loop */
 while(1)
 {
 /* Clear old bar graph lines */
 LCD_SetTextColor(Blue); 
 LCD_DrawLine( 121, (uint16_t)(60 - memsX/2), 16, Vertical);
 LCD_DrawLine( 145, (uint16_t)(60 - memsY/2), 16, Vertical);
 LCD_DrawLine( 169, (uint16_t)(60 - memsZ/2), 16, Vertical);
 LCD_SetTextColor(Green); /* Read X */
 memsX = (int8_t)(I2C_ReadDeviceRegister(MEMS_I2C_ADDR, MEMS_OutX));
 sprintf(lcdLine, ''MEMS X %+2d '', memsX);
 LCD_DisplayStringLine(Line5, (uint8_t*)lcdLine);
 LCD_DrawLine( 121, (uint16_t)(60 - memsX/2), 16, Vertical); /* Read Y */
 memsY = (int8_t)I2C_ReadDeviceRegister(MEMS_I2C_ADDR, MEMS_OutY);
 sprintf(lcdLine, ''MEMS Y %+2d '', memsY);
 LCD_DisplayStringLine(Line6, (uint8_t*)lcdLine);
 LCD_DrawLine( 145, (uint16_t)(60 - memsY/2), 16, Vertical);
 
 /* Read Z */
 memsZ = (int8_t)I2C_ReadDeviceRegister(MEMS_I2C_ADDR, MEMS_OutZ);
 sprintf(lcdLine, ''MEMS Z %+2d '', memsZ);
 LCD_DisplayStringLine(Line7, (uint8_t*)lcdLine);
 LCD_DrawLine( 169, (uint16_t)(60 - memsZ/2), 16, Vertical); /* Read Status Register */
 memsData = I2C_ReadDeviceRegister(MEMS_I2C_ADDR, MEMS_Status_Reg);
 sprintf(lcdLine, ''Status %X'', memsData);
 LCD_DisplayStringLine(Line8, (uint8_t*)lcdLine); #ifdef DEBUG_TRACE_ENABLED
 if ( (++lpCnt % 20) == 0 )
 {
 printf(''Cycle %d completed OK
'', lpCnt );
 }
 #endif /* 100mSec delay */
 Delay(10);
 }
 } 

eos
Associate II
Posted on May 17, 2011 at 14:09

Thanks for answer ... this damn sharepoint forum alert didn't work :(

I found also a way to works with mems by adpating the eeprom demo but it doesn't use interrupt yet. 

I'll try your code and finish to debug mine and post result here.