• AVR Freaks

Hot!Serial Communication configures

Author
john_ive
Super Member
  • Total Posts : 193
  • Reward points : 0
  • Joined: 2017/05/22 22:22:08
  • Location: 0
  • Status: offline
2019/04/04 22:04:09 (permalink)
0

Serial Communication configures

In my project i'm using PIC18F4520 controller.In this project i'm using an keypad which connected with  TX and RX pins.
Now i'm going to use these pins for communication also.
 
Shall I connect the keypad along with communication.?
When the program is started,shall we change the pin config for communication purpose only..?
During operation time(when the communication is started),we wont use keypad.
 
Is this is correct..?shall we use like this..?
#1

17 Replies Related Threads

    john_ive
    Super Member
    • Total Posts : 193
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/04 22:32:55 (permalink)
    0
    The circuit will be like this...
    The COM connector is used for communication.

    Attached Image(s)

    #2
    jack@kksound
    code tags!
    • Total Posts : 3183
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/05 08:24:50 (permalink)
    +1 (1)
    Parallel connection of devices on the same I/O pins can work but only if the two devices do not attempt to drive (be an output) the pins at the same time. You must ensure that this does not happen or figure out how to sort it out if it does.
    #3
    john_ive
    Super Member
    • Total Posts : 193
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/06 23:43:20 (permalink)
    0
    In UART communication,I tried to send HEX value like below code,

     while (1) {
            while (TXIF == 0);
            TXREG =0xFF;
        }

     
    But there is no response in receiver side.
     
    If I tried with decimal like 1,2,3 means working fine.
    How to solve this issue..?
     
     
    #4
    1and0
    Access is Denied
    • Total Posts : 9027
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Serial Communication configures 2019/04/07 00:00:22 (permalink)
    +1 (1)
    What is on the receiver side?  Does it support receiving 0xFF?
    #5
    crosland
    Super Member
    • Total Posts : 1568
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: Serial Communication configures 2019/04/07 02:59:08 (permalink)
    0
    john_ive
    In UART communication,I tried to send HEX value like below code,

     
     while (1) {
            while (TXIF == 0);
            TXREG =0xFF;
        }
     

     
    But there is no response in receiver side.
     
    If I tried with decimal like 1,2,3 means working fine.
    How to solve this issue..?
     
     


    What is the receiver? A terminal emulator program? What response did you expect?
     
    A terminal emulator will be expecting ASCII. 0xFF is not a printable ASCII character.
    #6
    john_ive
    Super Member
    • Total Posts : 193
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/10 01:37:21 (permalink)
    0
    I have to send hex value using uart communication.
    so,

    int n;
    char hexaDeciNum[3];

    void decToHexa(int n) {
        int i = 0;
        while (n != 0) {
            // temporary variable to store remainder
            int temp = 0;
            // storing remainder in temp variable.
            temp = n % 16;
            // check if temp < 10
            if (temp < 10) {
                hexaDeciNum[i] = temp + 48;
                i++;
            } else {
                hexaDeciNum[i] = temp + 55;
                i++;
            }
            n = n / 16;
        }
    }

    this code is used to convert the decimal into hex values.
     
    It working fine but the output value is inverted.
    For decimal 125,hex id 7D,but the output from the controller is D7.
     
    please help to invert the value in output and have to combine the output into single value to send through uart communication.
    #7
    crosland
    Super Member
    • Total Posts : 1568
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: Serial Communication configures 2019/04/10 02:45:00 (permalink)
    +1 (1)
    Is the keypad RS-232 or logic level signals?
     
    If it's a keypad, does it also have a display? How do you know the value is inverted?
    post edited by crosland - 2019/04/10 02:46:21
    #8
    john_ive
    Super Member
    • Total Posts : 193
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/10 02:57:27 (permalink)
    0
    crosland
    Is the keypad RS-232 or logic level signals?
     
    If it's a keypad, does it also have a display? How do you know the value is inverted?


    Stimulated in proteus and got inverted value.
    #9
    pcbbc
    Super Member
    • Total Posts : 910
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/10 03:28:40 (permalink)
    0
    #include <stdint.h>
    #include <stdio.h>

    char hexaDeciNum[5];

    void decToHexa(uint16_t n) {
        sprintf(hexaDeciNum, "%X", n);    
    }

    #10
    john_ive
    Super Member
    • Total Posts : 193
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/10 03:31:14 (permalink)
    0
    Inverting result is rectified by reading value in reverse.
    How to combine 7 and D from separate array into single 7D for transfer..?
    #11
    pcbbc
    Super Member
    • Total Posts : 910
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/10 04:14:37 (permalink)
    +1 (1)
    john_ive
    Inverting result is rectified by reading value in reverse.
    How to combine 7 and D from separate array into single 7D for transfer..?

    Why bother splitting them in the first place?
    How exactly are you expecting the non-ASCII character 0xD7 to be interpreted at the other end?
    #include <stdlib.h>
    uint16_t val = (uint16_t)strtol(hexaDeciNum, NULL, 16);

    post edited by pcbbc - 2019/04/10 04:17:01
    #12
    john_ive
    Super Member
    • Total Posts : 193
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/10 04:33:15 (permalink)
    0
    pcbbc
    john_ive
    Inverting result is rectified by reading value in reverse.
    How to combine 7 and D from separate array into single 7D for transfer..?

    Why bother splitting them in the first place?
    How exactly are you expecting the non-ASCII character 0xD7 to be interpreted at the other end?
    #include <stdlib.h>
    uint16_t val = (uint16_t)strtol(hexaDeciNum, NULL, 16);



    Can you explain this one please..?
    #13
    pcbbc
    Super Member
    • Total Posts : 910
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/10 05:01:19 (permalink)
    +2 (2)
    #14
    john_ive
    Super Member
    • Total Posts : 193
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/10 05:08:41 (permalink)
    0
    There are two keypad to increase and decrease the values.
    If the key 1 is pressed means hex value which transferred through the UART have to increase from 0X00 to 0XFF.
    If the key 2 is pressed means hex value which transferred through the UART have to decrease from 0XFF to 0X00.

    How to do this operation..?
    #15
    pcbbc
    Super Member
    • Total Posts : 910
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Serial Communication configures 2019/04/10 05:23:20 (permalink)
    0
    uint8_t value;
    if (key_1_pressed && value < 0xFF) value++;
    if (key_2_pressed && value > 0x00) value--;

    #16
    crosland
    Super Member
    • Total Posts : 1568
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: Serial Communication configures 2019/04/10 06:10:59 (permalink)
    0
    john_ive
    crosland
    Is the keypad RS-232 or logic level signals?
     
    If it's a keypad, does it also have a display? How do you know the value is inverted?


    Stimulated in proteus and got inverted value.




    So why did you say it was connected to a keypad???????
    #17
    qhb
    Superb Member
    • Total Posts : 9977
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: Serial Communication configures 2019/04/10 06:33:54 (permalink)
    +1 (1)
    The OP is saying "inverted" when he really means the first and second characters are swapped.
    They are swapped because that is how his decToHexa() is storing the output characters into the output array.
    i.e. the lower nybble goes into hexaDeciNum[0] and the upper nybble goes into hexaDeciNum[1]
    then he tries to output it as a string, so naturally the digits are swapped.
     
    #18
    Jump to:
    © 2019 APG vNext Commercial Version 4.5