Hello World - STM32 microcontrolador ARM

A continuación se presenta un "Hello World". Un LED ON/OFF cada 1 segundo. El estado de un botón es revisado cada 1 segundo y se el estado el alto, un LED cambia su estado actual.

La familia de microcontroladores STM32 están basados en la arquitectura ARM Cortex y son de alto desempeño. La documentación disponible es amplia y compleja, a veces tan densa que confunde al desarrollador y lo aleja de su objetivo.

Esperamos sea el primero de una serie de tutoriales.

-Código
-Código documentación exhaustiva

Compilador MikroC Pro for ARM

Código 


void main() {
     GPIO_Digital_Output(&GPIOA_BASE,_GPIO_PINMASK_0 | _GPIO_PINMASK_3);
     GPIO_Digital_Input(&GPIOB_BASE,_GPIO_PINMASK_0);
     GPIOA_ODR=0;
     while (1){
       delay_ms(1000);
       GPIOA_ODRbits.ODR3 = ~GPIOA_ODRbits.ODR3;
       if(GPIOB_IDR.F0)
       {
        GPIOA_ODRbits.ODR0= ~GPIOA_ODRbits.ODR0;
        }
     }
}


Código documentación exhaustiva  

/*
 * Project name:
     <Lab00> (<Led blinking on PORTA.F0 using Me libraries and an input review>)
 * Copyright:
     (c) <Vinicio Gómez, 03 June 2014>
 * Revision History:
     - initial release;
 * Status:
     <100% completed.>
 * Description:
     <Hellow world. Led blinking using GPIO library>
 * Test configuration:
     Device:          STM32F107VC
                      http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/CD00220364.pdf
     Dev.Board:       EasyMx v7 for STM(R) ARM(R)
                      http://www.mikroe.com/easymx-pro/stm32/
     Oscillator:      HSE-PLL, 16.000MHz
     Ext. Modules:    None.
     SW:              mikroC PRO for ARM
                      http://www.mikroe.com/mikroc/arm/
 * NOTES:
     - Turn ON PORTA LEDs at SW15 (board specific).
     - CONFIG WORDS
     RCC_CR    : $400FE060 : 0x15090081
     RCC_CFGR  : $40021004 : 0x00000001
     RCC_CFGR2 : $400FE060 : 0x00000000
 */
void main() {
     //PORTA <0,3> as digital input
     //GPIO_Digital_Output() is a library from Me
     //& points to the address of the object in memory
     //&GPIOA_BASE points to the address of the register of the port
     //That address (for PORTA) is 0x40010800
     //_GPIO_PIN_x helps to select the desired pin to applied the option.
     //x could be 0-15
     // | is a OR bitwise operator
     GPIO_Digital_Output(&GPIOA_BASE,_GPIO_PINMASK_0 | _GPIO_PINMASK_3);
     //PORTA <1> as digital input
     GPIO_Digital_Input(&GPIOB_BASE,_GPIO_PINMASK_0);
     //set low
     GPIOA_ODR=0;
     //main loop
     while (1){
       //wait 1 sec.
       //delay_ms() is a function of Me
       delay_ms(1000);
       //toggle PORTA.F3
       GPIOA_ODRbits.ODR3 = ~GPIOA_ODRbits.ODR3;
       //read the state of the PORTB.F0
       //if it is high
       if(GPIOB_IDR.F0)
       {
        //toggle PORTA.F0
        GPIOA_ODRbits.ODR0= ~GPIOA_ODRbits.ODR0;
        }
     }
}


No hay comentarios:

Publicar un comentario