//STM32F0 Reference manual PG 127/742
Turn on/off a Pin (Example Pin C8)
/* Enable clock for GPIOC */
RCC->AHBENR |= (1 << 19);
GPIOC->MODER |= (1 << 16);//Set pin C8 as output
GPIOC->OTYPER &= ~(1 << 8);//Set pin 8 output as internal push-pull
GPIOC->BSRR |= (1 << 24);//Turn Pin C8 off
GPIOC->BSRR |= (1 << 8);//Turn C8 on
Read a pin (Example Pin A0)
RCC->AHBENR |= (1 << 17); /* Enable GPIOA clock */
GPIOA->PUPDR |= (1 << 0); /* PA.0 is Pull up */
if((GPIOA->IDR & (1 << 0))==(1 << 0))//read pin state
{
//High
}
else
{
//Low
}
Set up external pin interrupt (Example Pin A0)
Config pin as input (above)
EXTI->IMR |= (1 << 0); //unmask External interrupt line 0 (PA0)
EXTI->RTSR |= (1 << 0); //Enable rising edge trigger of line 0
EXTI->FTSR |= (1 << 0); //Enable falling edge trigger of line 0
NVIC_EnableIRQ(EXTI0_1_IRQn);//Enabe EXTI0_1 IRQ
put this segment in the source file
//use extern "C" if the file is .cpp
extern "C" {
void EXTI0_1_IRQHandler(void)
{
//to do
}
}
Friday, June 1, 2012
Sunday, March 25, 2012
I2C Write, Read sequence
Write
Start, Write_Address, Data_Bytes, Stop
Read
Start, Write_Address, Register_Address, Read_Address, Stop
Start, Write_Address, Data_Bytes, Stop
Read
Start, Write_Address, Register_Address, Read_Address, Stop
Subscribe to:
Posts (Atom)