Hi,
I need some assistance on the external interrupt.
I was trying to make my MEMS more stable, therefor, I've made some hardware changes (adding the 1uH inductor) as suggested here, but the results didn't came as I expected (a minor variance on the MEMS x,y,z).
I'm using the Mems 1.1 application to check the out coming results and I manage to use this small alteration on the Circle OS (v3.7) source code to have a much better stability.
I don't know how to configure an External Interrupt on PB5, my idea is to use this external interrupt to avoid using the Timer2 interrupt to handle the MEMS's readout, since the timer2 is configured to happen each 3,66ms and I set the MEMS frequency to 40Hz...
Can anyone tell me how to configure the External interrupt pin? and how to handle it? If there is some code example that would be great.
Thanks in advance!
If anyone is interested on the modification that I made in order to acquire more stability, here is the parts where you should change it:
On the stm32f10x_circle_it.c:
/*******************************************************************************
*
* TIM2_IRQHandler
*
*******************************************************************************/
/**
*
* Handles the TIM2 global interrupt request.
*
**/
/******************************************************************************/
void TIM2_IRQHandler( void ) __attribute__ ((interrupt ("IRQ")));
void TIM2_IRQHandler( void )
{
#ifdef TIMING_ANALYSIS // to debug with a scope
GPIO_WriteBit( GPIOA, GPIO_Pin_7, Bit_RESET );
#endif
/* Clear TIM2 update interrupt */
TIM_ClearITPendingBit( TIM2, TIM_IT_Update );
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5))// check if PB5 is high
{
MEMS_Handler();
}
#ifdef TIMING_ANALYSIS // to debug with a scope
GPIO_WriteBit( GPIOA, GPIO_Pin_7, Bit_SET );
#endif
}
On the mems.c:
#define WRCTRL_REG2 0x21 //BFM: create as a test to setup the CrtReg2
#define RDCTRL_REG2 0xA1 /*!< Single Read CTRL_REG */
/*******************************************************************************
*
* MEMS_WakeUp
*
*******************************************************************************/
/**
* Wake Up Mems.
*
**/
/******************************************************************************/
static void MEMS_WakeUp( void )
{
u8 reg_val;
u8 reg_val2; // BFM: create as a test to setup the CrtReg2
reg_val2 = 0x00;
/* read RDCTRL_REG1 */
/* Chip Select low */
MEMS_ChipSelect( LOW );
/* Send "RDCTRL_REG1" instruction */
MEMS_SendByte( RDCTRL_REG1 );
reg_val = MEMS_SendByte( DUMMY_BYTE );
/* Chip Select high */
MEMS_ChipSelect( HIGH );
/* SET P0:P1 to '11' */
/* 0xC0 to wake up and 0x30 for full speed frequency (640 Hz). */
// BFM: changed to 0x00 for slow speed frequency (40Hz)
reg_val = reg_val | 0xC0 | 0x00;
/* Chip Select low */
MEMS_ChipSelect( LOW );
/* Send "WRCTRL_REG1" instruction */
MEMS_SendByte( WRCTRL_REG1 );
MEMS_SendByte( reg_val );
/* Chip Select high */
MEMS_ChipSelect( HIGH );
//BFM:Send "WRCTRL_REG2" instruction */
/* Chip Select low */
MEMS_ChipSelect( LOW );
/* Send "RDCTRL_REG2" instruction */
MEMS_SendByte( RDCTRL_REG2 );
reg_val = MEMS_SendByte( DUMMY_BYTE );
/* Chip Select high */
MEMS_ChipSelect( HIGH );
// BFM: changed to 0x04 for activate RDY function
reg_val2 = reg_val2 | 0x04;
MEMS_ChipSelect( LOW );
MEMS_SendByte( WRCTRL_REG2 );
MEMS_SendByte( reg_val2 );
MEMS_ChipSelect( HIGH );
}