BLINK LED NO SEGGER STUDIO E ARDUINO
ACESSANDO NINA B112
ACESSANDO NINA B112
O objetivo deste BLOG é fazer um blink de led utilizando um exemplo para o SEGGER STUDIO bem como Arduino, utilizando mapa de memória dos registradores do NINA B112.
Nos BLOGS anteriores foi visto como instalar o SEGGER STUDIO bem como ARDUINO para NINA B112.
Foi utilizado o EVK-NINA-B1 para testes.
Baseado no mapa de memória de GPIOS do NRF52832 abaixo e suas funções...
...foi desenvolvido o exemplo para acender um LED no formato do SEGGER STUDIO
#include <stdint.h>
#include <nrf_delay.h>
#include <boards.h> //LED_1 do NINA B112
#define GPIO_BASE 0x50000000
#define GPIO_OUTSET (*((uint32_t*) (GPIO_BASE + 0x508)))
#define GPIO_OUTCLR (*((uint32_t*) (GPIO_BASE + 0x50C)))
#define GPIO_PIN_CNF(pin) (*((uint32_t*) (GPIO_BASE + 0x700 + pin * 4)))
unsigned int LED = LED_1;
int main()
{
GPIO_PIN_CNF(LED) = 1;
while(1)
{
GPIO_OUTSET = (1 << LED);
nrf_delay_ms(500);
GPIO_OUTCLR = (1 << LED);
nrf_delay_ms(500);
}
return 0;
}
Abaixo em Arduino
#define GPIO_BASE 0x50000000
#define GPIO_OUTSET (*((uint32_t*) (GPIO_BASE + 0x508)))
#define GPIO_OUTCLR (*((uint32_t*) (GPIO_BASE + 0x50C)))
#define GPIO_PIN_CNF(pin) (*((uint32_t*) (GPIO_BASE + 0x700 + pin * 4)))
unsigned int LED = NINA_LED1;
void setup()
{
GPIO_PIN_CNF(LED) = 1;
}
void loop()
{
GPIO_OUTSET = (1 << LED);
delay(1000);
GPIO_OUTCLR = (1 << LED);
delay(1000);
}
No exemplo Arduino, nada impede voce usar pinMode() e digitalWrite() para programar e acessar o pino NINA_LED, mas é bom se acostumar com mapa de memória dos registradores (GPIO) para você nao ficar limitado aos comandos clássicos do Arduino. Com mapa de memória de GPIOS voce tem acesso direto aos registradores do NRF52832, no qual o NINA B122 é baseado.
Fontes:
http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fgpio.html
https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/introduction
https://gitlab.cba.mit.edu/pub/hello-world/nrf52
https://electronut.in/nrf52-baremetal/
Suporte:
suporte@smartcore.com.br
Nos BLOGS anteriores foi visto como instalar o SEGGER STUDIO bem como ARDUINO para NINA B112.
Foi utilizado o EVK-NINA-B1 para testes.
Baseado no mapa de memória de GPIOS do NRF52832 abaixo e suas funções...
...foi desenvolvido o exemplo para acender um LED no formato do SEGGER STUDIO
#include <stdint.h>
#include <nrf_delay.h>
#include <boards.h> //LED_1 do NINA B112
#define GPIO_BASE 0x50000000
#define GPIO_OUTSET (*((uint32_t*) (GPIO_BASE + 0x508)))
#define GPIO_OUTCLR (*((uint32_t*) (GPIO_BASE + 0x50C)))
#define GPIO_PIN_CNF(pin) (*((uint32_t*) (GPIO_BASE + 0x700 + pin * 4)))
unsigned int LED = LED_1;
int main()
{
GPIO_PIN_CNF(LED) = 1;
while(1)
{
GPIO_OUTSET = (1 << LED);
nrf_delay_ms(500);
GPIO_OUTCLR = (1 << LED);
nrf_delay_ms(500);
}
return 0;
}
Abaixo em Arduino
#define GPIO_BASE 0x50000000
#define GPIO_OUTSET (*((uint32_t*) (GPIO_BASE + 0x508)))
#define GPIO_OUTCLR (*((uint32_t*) (GPIO_BASE + 0x50C)))
#define GPIO_PIN_CNF(pin) (*((uint32_t*) (GPIO_BASE + 0x700 + pin * 4)))
unsigned int LED = NINA_LED1;
void setup()
{
GPIO_PIN_CNF(LED) = 1;
}
void loop()
{
GPIO_OUTSET = (1 << LED);
delay(1000);
GPIO_OUTCLR = (1 << LED);
delay(1000);
}
No exemplo Arduino, nada impede voce usar pinMode() e digitalWrite() para programar e acessar o pino NINA_LED, mas é bom se acostumar com mapa de memória dos registradores (GPIO) para você nao ficar limitado aos comandos clássicos do Arduino. Com mapa de memória de GPIOS voce tem acesso direto aos registradores do NRF52832, no qual o NINA B122 é baseado.
Fontes:
http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fgpio.html
https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/introduction
https://gitlab.cba.mit.edu/pub/hello-world/nrf52
https://electronut.in/nrf52-baremetal/
Suporte:
suporte@smartcore.com.br