C:\Users\LiTao\Desktop\ Child Intelligent Hardware data \NRF51822\NRF51822EK_TM supporting data \EK_TM test program
Serial test
1#include <stdint.h>2 3#include"nrf.h"4#include"simple_uart.h"5#include"Nrf_delay.h"6#include"nrf_gpio.h"7 8uint8_t Simple_uart_get (void)9 {Ten while(Nrf_uart0->events_rxdrdy! =1) One { A //Wait for RXD data to be received - } - theNrf_uart0->events_rxdrdy =0; - return(uint8_t) Nrf_uart0->RXD; - }//Wait until you can Rxdready directly, then set the flag bit to 0 and return the received data (data in rxd) - + BOOLSimple_uart_get_with_timeout (int32_t Timeout_ms, uint8_t *rx_data) - { + BOOLRET =true; A at while(Nrf_uart0->events_rxdrdy! =1) - { - if(timeout_ms-->=0) - { - //wait in 1ms chunk before checking for status -Nrf_delay_us ( +); in } - Else to { +RET =false; - Break; the } *}//Wait for RXD data to be received $ Panax Notoginseng if(Timeout_ms >=0) - { the //clear the event and set Rx_data with received byte +Nrf_uart0->events_rxdrdy =0; A*rx_data = (uint8_t) nrf_uart0->RXD; the } + - returnret; $ }//Wait a certain time and then receive $ - voidsimple_uart_put (uint8_t cr) - { theNrf_uart0->txd =(uint8_t) CR; - Wuyi while(Nrf_uart0->events_txdrdy! =1) the { - //Wait for TXD data to be sent Wu } - AboutNrf_uart0->events_txdrdy =0; $ } - - voidSimple_uart_putstring (Constuint8_t *str) - { Auint_fast8_t i =0; +uint8_t ch = str[i++]; the while(ch! =' /') - { $ simple_uart_put (CH); theCH = str[i++]; the } the } the - voidSimple_uart_config (uint8_t rts_pin_number, in uint8_t Txd_pin_number, the uint8_t Cts_pin_number, the uint8_t Rxd_pin_number, About BOOLHWFC) the { the Nrf_gpio_cfg_output (txd_pin_number); the nrf_gpio_cfg_input (Rxd_pin_number, nrf_gpio_pin_nopull); + -Nrf_uart0->pseltxd =Txd_pin_number; theNrf_uart0->pselrxd =Rxd_pin_number;Bayi the if(HWFC) the { - Nrf_gpio_cfg_output (rts_pin_number); - nrf_gpio_cfg_input (Cts_pin_number, nrf_gpio_pin_nopull); theNrf_uart0->pselcts =Cts_pin_number; theNrf_uart0->pselrts =Rts_pin_number; theNrf_uart0->config = (uart_config_hwfc_enabled <<uart_config_hwfc_pos); the } - theNrf_uart0->baudrate = (uart_baudrate_baudrate_baud38400 <<uart_baudrate_baudrate_pos); thenrf_uart0->enable = (uart_enable_enable_enabled <<uart_enable_enable_pos); theNRF_UART0->TASKS_STARTTX =1;94Nrf_uart0->tasks_startrx =1; theNrf_uart0->events_rxdrdy =0; the}
Links:Http://pan.baidu.com/s/1i31tNBR
7. Serial Port