MCU UART communication with Touch Screen

Thread Starter

jeffy123

Joined Jan 21, 2013
6
Dear All,

I am working with 16 bit MCU for communicating with a TC through a serial Port I have one problem when sending commands from mcu to tc, ie,i want to send a command like "?01SRW000615F"from mcu to TC for that I wrote a code, when testing in hyperterminal its working,but when connecting to TC its not working means no response from TC,but the same code in hyperterminal when pressing enter its passing to TC, its works.I dont know why MCU not sending to TC,

I found out one thing is when pressing enter in hyperterminal then only this command send to TC so add a'\r' in my program then also not working.

Normally MCU transmit one charater at a time,may be this is the issue,anyone have idea how to send a bunch of charaters at a time. Plz help me to find a solution.

All the commands I used in the program are right.
 

t06afre

Joined May 11, 2009
5,934
Then working with serial communication very much can go wrong. For a starter do you use proper TTL to RS232 level conversion? It is also true that you only can send one char at the time using RS232. So you must build a software function that receive a string and send one char at the time. As a start I would have hooked my terminal program to the MCU first. To check what kind of info that is sent from the MCU. Then you get this working you may hook up your touch screen module
 

MrChips

Joined Oct 2, 2009
30,824
There are a number of things to check.

1) Check that the communications protocol is the same on both ends, number of data bits, parity, stop bits
2) Confirm the baud rate is the same at both ends
3) Check that CR is being sent
4) Check that LF is not being sent
 

Thread Starter

jeffy123

Joined Jan 21, 2013
6
all the configurations are right because i can send commands from Touch screen to mcu,
and also when i connect this mcu to hyperterminal then it will transmit command to hyperterminal,i dont know why it is not working when i connect to TC. Can anyone send a sample program for transmiting a string to an external device with an enter key.
 

thatoneguy

Joined Feb 19, 2009
6,359
When viewing the output in hyper term, does each command go on a new line?

What are you having hyper term send for EOL? CR+LF, CR, or LF?

Rich (BB code):
sprintf(buffer, "string to be built, using printf notation, such as %d, %x %c, etc\n", data, to, match, format, characters);
uart_write(buffer);
Use \r for carriage return, \n for newline, or \r\n for CR+LF
 

Thread Starter

jeffy123

Joined Jan 21, 2013
6
When I made changes in my code I got an error message in Touchscreen that means the mcu is sending something to TC,but not sending right data,what shall i do to send a command like ?01SRW000615F with a enter key,now what I did is I declarerd a char buffer of 12,& defined each variable into the array & include the enter key.
I think the problem is mcu is sending each variable with enter key,but i need a string together with enter key ,for that what shall I do, plz help me.
 

t06afre

Joined May 11, 2009
5,934
(Grin) well you have kind of pointed out what is wrong. And the solution will be to use the debugger. Also without knowing anything about which MCU and compiler you use it is hard give any help at all.
 

Thread Starter

jeffy123

Joined Jan 21, 2013
6
Thanks everyone ,now its working.I have some doubts in embedded c programming,I have a sample code work for Renesas R8C/26-R5F2127 mcu, in this they used as for eg. with extern keyword.
union byte_def byte_flag_0;
union byte_def byte_flag_1;
union byte_def byte_flag_2;
#define bf_timeup_1ms byte_flag_0.bit.b0
#define bf_timeup_10ms byte_flag_1.bit.b0
#define bf_timeup_100ms byte_flag_2.bit.b0 like this, what does this means,I think they defined each variable with a bit.But my main doubt is from where this byte_flag is getting a value,in that program there is no option to get a value, they simply mention 2 condtions like if (bf_timeup_1ms) or else. What does this means.Plz help me.
Purpose of this program is TX & RX.
 

Thread Starter

jeffy123

Joined Jan 21, 2013
6
plz anyone post a embedded C program for calculate BCC(Block Check Code).
How to cocncatenate two character array for eg char buf[0]='3'; char buf[1]='F',
I want result as buf[]="3F";

Plz give me a solution
 

t06afre

Joined May 11, 2009
5,934
plz anyone post a embedded C program for calculate BCC(Block Check Code).
How to cocncatenate two character array for eg char buf[0]='3'; char buf[1]='F',
I want result as buf[]="3F";

Plz give me a solution
Use a union.
A union is a variable that may hold (at different times) objects of different types and sizes, with the compiler keeping track of size and alignment requirements. Unions provide a way to manipulate different kinds of data in a single area of storage, without embedding any machine-dependent information in the program.
Rich (BB code):
union {
    unsigned short val;
    unsigned char bytes[2];
} u;
 
u.val = 12345;
printf(" %x %x\n",  u.bytes[1], u.bytes[0]);  /* little endian */
 
.....
output:
30 39
However a thing you should be aware of is endianness http://en.wikipedia.org/wiki/Endianness I do not now which endian you compiler use. For more info use a Google search for union c
 
Top