I am trying to send printf data to my uart device. I have suitablely written write_r() funciton.
The problems that I am having is,
- When I say
printf(" My name is sam \n I am fine "); - and in next time when i say
printf(" I am back ");
1st problem : I can see only "My name is Sam", then the cursor goes to next line and stops there.
2nd problem : "I am back" is not getting printed at all.
I tried by removing \n , still the 2nd printf doesn't get printed. There is nothing wrong with the uart.
Looks like then \ is reached the pointer is lost.
My Code
int write(int file, char *ptr, int len) { #if !defined( OUT_8 ) #define OUT_8(p,d) (*(volatile char *)(p) = (char)(d)) #endif #if !defined( IN_8 ) #define IN_8(p) ((*(volatile char *)(p))) #endif OUT_8(DUART1_UMCR1, 0x02); //Informs external modem or peripheral that the UART is ready for sending data OUT_8(DUART1_ULCR1, 0x03); OUT_8(DUART1_UIER1, 0x0f); OUT_8(DUART1_UFCR1, 0x8f); OUT_8(DUART1_UTHR, '\n'); OUT_8(DUART1_UTHR, '\r'); while (ptr!=NULL) { if (*ptr=='\n') // JUST A TRY to avoid \n bug { OUT_8(DUART1_UTHR, '\n'); wait(); *ptr++; *ptr++; OUT_8(DUART1_UTHR, *ptr++); // \n & \r when given through printf isNot working wait(); } OUT_8(DUART1_UTHR, *ptr++); // \n & \r when given through printf is not working wait(); // TODO: if(len==0) break; else len--; } OUT_8(DUART1_UMCR1, 0x00); // say that modem is not not ready. Connection over OUT_8(DUART1_UFCR1, 0x87); OUT_8(DUART1_ULCR1, 0x00); // Clear all the interrupts ! virtually shut the UART port errno = ENOSYS; return -1; }
'\\'. The newline is written as'\n'. Your code has 2 characters, but the string formed has only 1. The codeif(*ptr=='\n') { ...}has nothing to do with an occurrence of a backslash inptr.