In ANSII code 48 is '0', and for example adding 48 to 1 gives 49 which is '1'. Take a note how individual digits are sent. UART->UART_THR = Result + 48 // Sending out the digit Void PrintHEX(uint8_t* ptrBuffer, uint32_t Length)įor (uint32_t i = 0 i > 4 // Extracting higher half-byteīyteToSend = arHex // Getting readable char while( 0 = (UART->UART_SR & UART_SR_TXRDY)) Thus the algorithm of printing in HEX is following: first 0x is printed, then half byte is extracted, then that half byte will be an index in the following array: Prefix 0x means that number is represented in HEX. As you know ( don't you?) a byte is represented by two hexadecimal digits, 4 bits per each digit. We also need to be able to print number in hex, bin and decimal format. In future we are going to print USB device descriptors, for that more than just printing strings is needed. Now you can see that sending data via UART is really simple. Please note that I added #include UART.h to top of the main file to link our UART code and a call to UART_Init() in the main function.īuild it and upload to Arduino Due board then launch Docklight, the output should be following: PrintStr( " Hello World\r\n") // Testing call is here!!! So let's add them to project, then add following line to top of UART.c I'll put all code related to UART in two separate files: UART.h and UART.c. UART initialization consists of 3 stages: RX / TX pins configuration UART speed and parameters configuration and enabling clock to UART. But don't worry, in Arduino Due it all happens via USB cable and virtual COM port that is created by Arduino software (see previous article). Computers used to have COM ports (RS-232) for serial communication, UART is perfectly compatible with such ports except signal voltage levels. I will use UART (Universal Asynchronous Receiver Transmitter) for serial communication with my laptop. ![]() Then in the next article I'll briefly discuss TFT monitor and watchdog timer. ![]() In this article I'll show how to initialize serial communication component, create functions to print strings, hex, decimal and binary numbers. Two more things are needed to start dealing with USB, a serial communication with a computer and some kind of monitor to see stream video.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |