1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Serial comm between uC and PC...

Discussion in 'Microcontrollers' started by koolguy, Apr 26, 2013.

  1. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    In your code this is wrong:

    unsigned char *c;

    That is just a pointer.. there is no memory reserved for characters. you need to define it as an array:

    unsigned char c[20];

    You can change the number to whatever size array you need.
     
  2. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    will this will work??
    char d[10];
    char *c=d;
     
  3. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I think it working now!!
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland

    Hard to say.. Can you explain what that piece of code should do.
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    To change the function to a unblocking type.. Use the receive flag.

    Code (c):

    unsigned char HSerin()    
     {    
       if (RCIF)                     // Is there a character    
          return RCREG;                    // return character
       else
           return   255;      // Or return -1
      }
     
     
  7. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    what does this mean??
     
  8. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Nothing.. I think that was bad code from Ian. You can't return error codes in the same path you return data.. they need to be separated.
     
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    Yes you can if he uses ascii like I suggested a good while back.... This way he can learn software control..

    Ritesh... If you use ascii like I showed you, you only need 0 to 127 ascii characters... So if the function returns 255 ( -1) then you know that a character isn't here yet!!!
     
  10. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    True.. You just have to know what kind of data is coming in. I was thinking "in general".. which actually makes things very complicated..
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    I'm trying to simplify the serial transfer for Ritesh... Using binary data transfers wil be a tiny bit over his head... Be my guest if you can show him packet transfers.....
     
  12. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Ritesh just got the thing working when you came up with that unblocking code.. that made his head spin.
     
  13. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I have one question, can we transfer data from uC to PC via UART and then this data to another using team viewer sharing to PC...?
    I mean to say how to copy/move data to teamviwer from hyperterminal ?
     
  14. Brian Griffin

    Brian Griffin Member

    Joined:
    May 23, 2013
    Messages:
    49
    Likes:
    8
    Location:
    Kuala Lumpur
    Teamviewer is a remote control software. What has UART got to do with the Teamviewer?
     
  15. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I want to transfer data from hyper terminal window to another PC...
     
  16. Brian Griffin

    Brian Griffin Member

    Joined:
    May 23, 2013
    Messages:
    49
    Likes:
    8
    Location:
    Kuala Lumpur
    So you want to transfer datas together to two PCs?
     
  17. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Yessssss.........
     
  18. Brian Griffin

    Brian Griffin Member

    Joined:
    May 23, 2013
    Messages:
    49
    Likes:
    8
    Location:
    Kuala Lumpur
    It should be simple if you want to send the same piece of data to two PCs. Do you have another UART to USB converter for the other PC?
     
  19. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I will manage it....later.
    just i want to know procedure
     
  20. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,158
    Likes:
    339
    Location:
    Brisbane Australia
    Wow, 4 more pages in one day. Awesome.

    Mike.
     
  21. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I am trying to compare two string one stored in memory other is scanned..
    the problem is that while reading string from terminal i am using array the length will depend on it.
    so, comparing of string will be wrong can't we read string in such a way without using a fixed size and compare it???

    Code (text):
    unsigned char b[10];
    unsigned char *c="Hello";

    for(char x=0;x<6;x++){
    b[x]=HSerin();

    }

    int result = strncmp(c,b, compareLimit);

    if(result > 0){
    ch='a';
    HSerout(ch);
    }

    else if(result < 0)
            {
    ch='b';
    HSerout(ch);
            }
    else{
    ch='c';
    HSerout(ch);
    }
     

Share This Page