2010-09-28 5:09 AM
Mems on stm3210C eval
2011-05-17 5:09 AM
You can start with
http://www.st.com/stonline/products/literature/ds/12726/lis302dl.htm
if you have not done so.2011-05-17 5:09 AM
There is working mems driver code in the eval board firmware:
http://www.st.com/stonline/products/support/micro/files/stm3210c-eval_fw.zip
2011-05-17 5:09 AM
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,
2011-05-17 5:09 AM
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));
2011-05-17 5:09 AM
2011-05-17 5:09 AM
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);
}
}
2011-05-17 5:09 AM
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.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.