init
Dependencies: aconno_I2C Lis2dh12 WatchdogTimer
Diff: NRFuart.cpp
- Revision:
- 37:505ef618f06c
- Parent:
- 36:8e359069192b
- Child:
- 48:64b1613941d5
diff -r 8e359069192b -r 505ef618f06c NRFuart.cpp --- a/NRFuart.cpp Tue Jan 15 11:19:41 2019 +0000 +++ b/NRFuart.cpp Wed Jan 16 21:27:28 2019 +0000 @@ -1,9 +1,7 @@ -//bool NRFuart_enabled = false; #include "NRFuart.h" void NRFuart_init_nohwfc() { if(NRF_UART0->ENABLE == UART_ENABLE_ENABLE_Disabled) { - //Configure UART0 pins. nrf_gpio_cfg_output(PN_UART_TX); nrf_gpio_cfg_input(PN_UART_RX, NRF_GPIO_PIN_NOPULL); NRF_UART0->PSELTXD = PN_UART_TX; @@ -27,7 +25,34 @@ //NVIC_EnableIRQ(UART0_IRQn); //NVIC_SetVector(UART0_IRQn, (uint32_t) UART0_IRQHandler); } - //NRFuart_enabled = true; +}; +void NRFuart_init_hwfc() { + if(NRF_UART0->ENABLE == UART_ENABLE_ENABLE_Disabled) { + nrf_gpio_cfg_output(PN_UART_TX); + nrf_gpio_cfg_input(PN_UART_RX, NRF_GPIO_PIN_NOPULL); + NRF_UART0->PSELTXD = PN_UART_TX; + NRF_UART0->PSELRXD = PN_UART_RX; + NRF_UART0->PSELCTS = PN_UART_CTS; + NRF_UART0->PSELRTS = PN_UART_RTS; + NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Enabled; + NRF_UART0->BAUDRATE = NRF_UART_BAUDRATE_115200; + NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled; + NRF_UART0->EVENTS_RXDRDY = 0; + NRF_UART0->EVENTS_TXDRDY = 0; + NRF_UART0->EVENTS_ERROR = 0; + NRF_UART0->EVENTS_TXDRDY = 0; + NRF_UART0->TASKS_STARTRX = 1; + NRF_UART0->TASKS_STARTTX = 1; + //NRF_UART0->INTENCLR = 0xffffffffUL; + //NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Msk; //or + /*NRF_UART0->INTENSET = (UART_INTENSET_RXDRDY_Set << UART_INTENSET_RXDRDY_Pos) | + (UART_INTENSET_TXDRDY_Set << UART_INTENSET_TXDRDY_Pos) | + (UART_INTENSET_ERROR_Set << UART_INTENSET_ERROR_Pos);*/ + //NVIC_ClearPendingIRQ(UART0_IRQn); + //NVIC_SetPriority(UART0_IRQn, 1); //3 + //NVIC_EnableIRQ(UART0_IRQn); + //NVIC_SetVector(UART0_IRQn, (uint32_t) UART0_IRQHandler); + } }; void NRFuart_uninit() { if (NRF_UART0->ENABLE == UART_ENABLE_ENABLE_Enabled) { @@ -40,7 +65,6 @@ NRF_UART0->PSELRXD = 0xFFFFFFFF; NRF_UART0->PSELRTS = 0xFFFFFFFF; NRF_UART0->PSELCTS = 0xFFFFFFFF; - //NRFuart_enabled = false; } }; void NRFuart_putc(char byte) { @@ -54,19 +78,25 @@ }; void NRFuart_puts(char* bytes) { if (!NRF_UART0->ENABLE) NRFuart_init_nohwfc(); - for(int i = 0; bytes[i] != '\0'; i++) { + uint32_t safetycounter = 0; + for(int i = 0; bytes[i] != 0x00; i++) { NRFuart_putc(bytes[i]); + safetycounter ++; + if (safetycounter > 10000) break; } }; void NRFuart_puts_debug(char* bytes) { if (!NRF_UART0->ENABLE) NRFuart_init_nohwfc(); - for(int i = 0; bytes[i] != '\0'; i++) { + uint32_t safetycounter = 0; + for(int i = 0; bytes[i] != 0x00; i++) { NRFuart_putc(bytes[i]); + safetycounter ++; + if (safetycounter > 10000) break; } NRFuart_putc('\n'); }; void debug_prep(){ - memset(GLOBAL_debug_buffer, '\0', sizeof(GLOBAL_debug_buffer)); + memset(GLOBAL_debug_buffer, 0x00, sizeof(GLOBAL_debug_buffer)); } void debug_exe(){ NRFuart_puts_debug(GLOBAL_debug_buffer); @@ -85,8 +115,10 @@ static char buffer[200]; int charindex = 0; memset(buffer,0x00,sizeof(buffer)); - while(1) { + uint32_t safetycounter = 0; + while(1 && safetycounter < 10000) { if (NRF_UART0->EVENTS_RXDRDY == 0) { + safetycounter ++; //Nothing available from the UART. continue; } else {