Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdarg.h>
- #include "bsp.h"
- #include "app_uart.h"
- void uartEventHandler(app_uart_evt_t *event) {}
- uint32_t uartInit()
- {
- app_uart_comm_params_t uartParams =
- {
- RX_PIN_NUMBER,
- TX_PIN_NUMBER,
- RTS_PIN_NUMBER,
- CTS_PIN_NUMBER,
- APP_UART_FLOW_CONTROL_DISABLED,
- false,
- UART_BAUDRATE_BAUDRATE_Baud115200 // 57600 // 115200
- };
- uint32_t error;
- APP_UART_FIFO_INIT(&uartParams, 32, 256, uartEventHandler, APP_IRQ_PRIORITY_LOW, error);
- return error;
- }
- void dbgOut(const char *s, ...)
- {
- char buf[256] = { 0 };
- va_list v;
- va_start(v, s);
- vsnprintf(buf, 256, s, v);
- va_end(v);
- for(uint8_t i = 0; i <= 255 && buf[i]; ++i) app_uart_put(buf[i]);
- }
- /*
- * Stuff happens here
- */
- volatile bool timeout = false;
- void TIMER1_IRQHandler()
- {
- if(NRF_TIMER1->EVENTS_COMPARE[0])
- {
- NRF_TIMER1->EVENTS_COMPARE[0] = 0;
- timeout = true;
- }
- }
- int main()
- {
- uartInit();
- dbgOut("Hello World!\r\n");
- NRF_TIMER1->TASKS_STOP = 1;
- NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
- NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos;
- NRF_TIMER1->PRESCALER = 9;
- NRF_TIMER1->TASKS_CLEAR = 1;
- NRF_TIMER1->CC[0] = 31250;
- NRF_TIMER1->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;
- NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos;
- NVIC_EnableIRQ(TIMER1_IRQn);
- NRF_TIMER1->TASKS_START = 1;
- while(1)
- {
- if(timeout)
- {
- dbgOut("timeout\r\n");
- timeout = false;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement