MCU UART communication with Touch Screen

Discussion in 'Embedded Systems and Microcontrollers' started by jeffy123, Jan 21, 2013.

  1. jeffy123

    Thread Starter New Member

    Jan 21, 2013
    6
    0
    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.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,429
    3,360
    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
     
  4. jeffy123

    Thread Starter New Member

    Jan 21, 2013
    6
    0
    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.
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    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?

    Code ( (Unknown Language)):
    1.  
    2. sprintf(buffer, "string to be built, using printf notation, such as %d, %x %c, etc[B]\n[/B]", data, to, match, format, characters);
    3. uart_write(buffer);
    4.  
    Use \r for carriage return, \n for newline, or \r\n for CR+LF
     
  6. jeffy123

    Thread Starter New Member

    Jan 21, 2013
    6
    0
    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.
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    (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.
     
  8. jeffy123

    Thread Starter New Member

    Jan 21, 2013
    6
    0
    I am using Renesas R8C/26-R5F2127 mcu & I am Using High Embedded Workshop(HEW) compiler.
     
  9. jeffy123

    Thread Starter New Member

    Jan 21, 2013
    6
    0
    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.
     
  10. jeffy123

    Thread Starter New Member

    Jan 21, 2013
    6
    0
    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
     
  11. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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.
    Code ( (Unknown Language)):
    1.  
    2. union {
    3.     unsigned short val;
    4.     unsigned char bytes[2];
    5. } u;
    6.  
    7. u.val = 12345;
    8. printf(" %x %x\n",  u.bytes[1], u.bytes[0]);  /* little endian */
    9.  
    10. .....
    11. output:
    12. 30 39
    13.  
    14.  
    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
     
Loading...