We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hello dear all, i am working on a project that when i send a hex packet i can show that in my pc by uart. but i cant see the packet it just show zero. i write my code here:
#include <LPC17xx.h> #include <stdio.h> #include "uart.h" unsigned char j[8]; void Delay (uint32_t Time) { uint32_t i; i = 0; while (Time--) { for (i = 0; i < 5000; i++); } } void read_uart2(void){ unsigned char j[8]; char temp; int i=0; for (i=0; i<7; i++) { temp=UART2_GetChar(); j[i]=temp; i++; }; } int main(void) { int i=0 ; // unsigned char i[8]; unsigned char lcd_buf[8]; SystemInit(); UART0_Init(); UART2_Init(); read_uart2(); while (1) { UART2_SendString("-LPC1768 -\r\n"); UART2_SendString((unsigned char *)lcd_buf); sprintf(lcd_buf,"counter: %x %x %x %x %x %x %x %x\r\n\n",j[0],j[1],j[2],j[3],j[4],j[5],j[6],j[7]); Delay(4000); } }
So use a debugger, and understand what your code and the peripherals are doing.
Have the sprintf() fill the string *before* trying to output it.