+ Reply to Thread
Page 1 of 2
1 2 Last
Results 1 to 15 of 16

Thread: rs232 problem

  1. #1
    tss
    tss is offline
    tss Newbie
    Join Date
    May 2009
    Posts
    13

    rs232 problem

    i was connecting rs232 DB9 to PIC16f877A and using hyperterminal to show the data. it only work when i keep on switching on and off power supply. it was no respond when i switch on the powerr supply constanly. anyone can tell me what is the problem ? below is my programming code.


    unsigned short temp_res;

    void main() {
    USART_Init(19200);


    ADCON1 = 0;
    TRISA = 0xFF;
    do {
    temp_res = ADC_Read(2) >> 2;
    USART_Write(temp_res);
    Delay_ms(100);
    } while (1);
    }


  2. #2
    binzer Okay
    Join Date
    Apr 2008
    Location
    Oxford, Ct USA
    Posts
    144
    Blog Entries
    2

    Quote Originally Posted by tss View Post
    i was connecting rs232 DB9 to PIC16f877A and using hyperterminal to show the data. it only work when i keep on switching on and off power supply. it was no respond when i switch on the powerr supply constanly. anyone can tell me what is the problem ? below is my programming code.

    Code:
    unsigned short temp_res;
    
    void main() {
      USART_Init(19200);
    
    
      ADCON1 = 0;
      TRISA  = 0xFF;
      do {
        temp_res = ADC_Read(2) >> 2;
        USART_Write(temp_res);
        Delay_ms(100);
      } while (1);
    }
    


    the while (1) at the end just loops there, so your program will run once and sit at the loop (if I remember correctly).
    Last edited by binzer; 11th June 2009 at 05:49 PM.

  3. #3
    tss
    tss is offline
    tss Newbie
    Join Date
    May 2009
    Posts
    13

    so did you mean i have to change my program from

    do{
    ..... } while (1);

    to

    while (1) {
    ..... };

    it doenst work when i connected rs232 pin 2 (Rx) to MAX232 pin 14(T1out) without moving.
    it work only when rs232 pin (Rx) keep on touching and removing from MAX232 pin 14(T1out).
    once pin 2 touched pin 14, hyperterminal will shows the data then stop. to receive data continuously, i have to keep on touching and removing the pin. do you know what is the problem ?

  4. #4
    binzer Okay
    Join Date
    Apr 2008
    Location
    Oxford, Ct USA
    Posts
    144
    Blog Entries
    2

    Quote Originally Posted by tss View Post
    so did you mean i have to change my program from

    do{
    ..... } while (1);

    to

    while (1) {
    ..... };

    it doenst work when i connected rs232 pin 2 (Rx) to MAX232 pin 14(T1out) without moving.
    it work only when rs232 pin (Rx) keep on touching and removing from MAX232 pin 14(T1out).
    once pin 2 touched pin 14, hyperterminal will shows the data then stop. to receive data continuously, i have to keep on touching and removing the pin. do you know what is the problem ?
    It sounds like a bad ground or a ground loop between the items. Can you post your circuit?
    Do you have decoupling caps on the pic and MAX232? Is your power supply clean (noise)?

  5. #5
    tss
    tss is offline
    tss Newbie
    Join Date
    May 2009
    Posts
    13

    schematic

    this is my schematic. it only work when i unground pin 15. i also found that my hyperterminal received data without pic16f877. actually hyperterminal should not receive any data without pic16f877 am i right ?
    Attached Files

  6. #6
    3v0
    3v0 is online now
    3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent
    Join Date
    Jul 2006
    Location
    USA
    Posts
    6,399
    Blog Entries
    11

    Quote Originally Posted by tss View Post
    so did you mean i have to change my program from

    do{
    ..... } while (1);

    to

    while (1) {
    ..... };
    No, it will work both ways. You can check the web for syntax.

    Code:
      do {
        temp_res = ADC_Read(2) >> 2;
        USART_Write(temp_res);
        Delay_ms(100);
      } while (1);
    
    I am guessing you expect to see the result of the ADC_Read display on hyperterminal.

    Code:
    void Usart_Write(unsigned short data);
    
    If the ADC conversion returns 65 you will see the letter 'A' in hyperterm. 66 will result in 'B'. Because 65 is the ascii value for A and 66 is the ascii value for B.

    You can either use printf which has the ability to convert you number to a string (ie 65 becomes the char 6 followed by the char 5) or itoa (int to ascii) to get a string of characters and use Usart_Write to send each out in order.

    Both of these are somewhat compiler dependant and there is no mention of which complier you are using.

    I did not look at the schematic.
    Please post questions to the forums. PM's are for personal communication.

    BCHS/3v0's Tutorials
    Junebug USB PIC programmer kit., USB Bit Whacker,
    The 15 Minute Printed Circuit Board! (+drill time)

  7. #7
    binzer Okay
    Join Date
    Apr 2008
    Location
    Oxford, Ct USA
    Posts
    144
    Blog Entries
    2

    Quote Originally Posted by tss View Post
    this is my schematic. it only work when i unground pin 15. i also found that my hyperterminal received data without pic16f877. actually hyperterminal should not receive any data without pic16f877 am i right ?
    Picture is too fuzzy for me to see. I would disconnect the RX on the pic as you may be generating junk on the input, do you have interrupts shut off on the Usart?
    Mike.

  8. #8
    tss
    tss is offline
    tss Newbie
    Join Date
    May 2009
    Posts
    13

    Quote Originally Posted by binzer View Post
    Picture is too fuzzy for me to see. I would disconnect the RX on the pic as you may be generating junk on the input, do you have interrupts shut off on the Usart?
    Mike.
    i used the program below to test my hyperterminal but i found that my pic16f877a pin RC6/Tx and RC7/Rx dont have output voltage. that means max232 did not receive any data from pic16f877. what is the problem ?

    unsigned short temp_res;

    void main() {
    USART_Init(19200); // Initalize USART (19200 baud rate, 1 stop bit, no parity...)

    // Select Vref and analog inputs, in order to use ADC_Read
    ADCON1 = 0; // All PORTA pins as analog, VDD as Vref
    TRISA = 0xFF; // PORTA is input

    do {
    temp_res = ADC_Read(2) ;
    USART_Write(temp_res); // Send ADC reading as byte
    Delay_ms(100);
    } while (1); // endless loop
    }

  9. #9
    tss
    tss is offline
    tss Newbie
    Join Date
    May 2009
    Posts
    13

    my circuit is currently working. the previous problems have been solved by changing capacitors and clock of pic16f877a and the program still remain the same.

    now i want to add Rf transmitter to pin RC6/Tx (pic16f877a) in order to transmit program to another computer using hyperterminal. please let me know if i am wrong. i hope can receive some comments from seniors again. thanks

  10. #10
    tss
    tss is offline
    tss Newbie
    Join Date
    May 2009
    Posts
    13

    Quote Originally Posted by 3v0 View Post
    No, it will work both ways. You can check the web for syntax.

    Code:
      do {
        temp_res = ADC_Read(2) >> 2;
        USART_Write(temp_res);
        Delay_ms(100);
      } while (1);
    
    I am guessing you expect to see the result of the ADC_Read display on hyperterminal.

    Code:
    void Usart_Write(unsigned short data);
    
    If the ADC conversion returns 65 you will see the letter 'A' in hyperterm. 66 will result in 'B'. Because 65 is the ascii value for A and 66 is the ascii value for B.

    You can either use printf which has the ability to convert you number to a string (ie 65 becomes the char 6 followed by the char 5) or itoa (int to ascii) to get a string of characters and use Usart_Write to send each out in order.

    Both of these are somewhat compiler dependant and there is no mention of which complier you are using.

    I did not look at the schematic.
    how if i want to transmit program using RF transceiver? can u give me some examples of transmitting program using RF transceiver? i am using microC compiler. i will connect RF receiver to computer using max232. i aim is to transmit program using RF transceiver and read the program on hyperterminal. please guide me.

  11. #11
    binzer Okay
    Join Date
    Apr 2008
    Location
    Oxford, Ct USA
    Posts
    144
    Blog Entries
    2

    Quote Originally Posted by tss View Post
    how if i want to transmit program using RF transceiver? can u give me some examples of transmitting program using RF transceiver? i am using microC compiler. i will connect RF receiver to computer using max232. i aim is to transmit program using RF transceiver and read the program on hyperterminal. please guide me.
    Many people use Manchester Coding to send data over RF, it would have to be implemented in your pic code or I think there are some rf tranceivers capable of doing that also.
    Mike.

  12. #12
    tss
    tss is offline
    tss Newbie
    Join Date
    May 2009
    Posts
    13

    Quote Originally Posted by binzer View Post
    Many people use Manchester Coding to send data over RF, it would have to be implemented in your pic code or I think there are some rf tranceivers capable of doing that also.
    Mike.
    if i use hyperterminal, do i need to use manchester coding again? or i can just direct send data without manchester coding by hyperterminal ? can you give some examples as references for me ? i am using mikroC compiler currently.

  13. #13
    binzer Okay
    Join Date
    Apr 2008
    Location
    Oxford, Ct USA
    Posts
    144
    Blog Entries
    2

    Quote Originally Posted by tss View Post
    if i use hyperterminal, do i need to use manchester coding again? or i can just direct send data without manchester coding by hyperterminal ? can you give some examples as references for me ? i am using mikroC compiler currently.
    Manchester Coding is used because it is more tolerant for non perfect transfer methods like rf or ir, you do not really need it for direct cable connections. If you encode it on one end you need to decode it on the other end. There may be info on Microchips site, but there have been postings on this before, check Nigels site as I believe he has info posted there.
    Mike.

    Check this thread.. RF module interface with PIC

    Also here is a chip that does the job and can be used on both ends. http://www.rfmodules.com.au/rm/products/ctr124.htm
    Last edited by binzer; 15th June 2009 at 12:07 PM.

  14. #14
    3v0
    3v0 is online now
    3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent
    Join Date
    Jul 2006
    Location
    USA
    Posts
    6,399
    Blog Entries
    11

    Forget about radio until after you have it working with wires (RS232).

    Neither of you have fixed the problem I pointed out in my previous post.
    Please post questions to the forums. PM's are for personal communication.

    BCHS/3v0's Tutorials
    Junebug USB PIC programmer kit., USB Bit Whacker,
    The 15 Minute Printed Circuit Board! (+drill time)

  15. #15
    binzer Okay
    Join Date
    Apr 2008
    Location
    Oxford, Ct USA
    Posts
    144
    Blog Entries
    2

    Quote Originally Posted by 3v0 View Post
    Forget about radio until after you have it working with wires (RS232).

    Neither of you have fixed the problem I pointed out in my previous post.
    Pardon me, I will refrain from further comments period.

+ Reply to Thread
Page 1 of 2
1 2 Last

Similar Threads

  1. Firefly 16F88 RS232 problem
    By futz in forum Micro Controllers
    Replies: 6
    Latest: 23rd February 2008, 01:04 PM
  2. AVR DDS ~ RS232 problem...
    By krazatchu in forum AVR
    Replies: 15
    Latest: 13th December 2007, 05:44 AM
  3. rs232 problem
    By handsprince in forum General Electronics Chat
    Replies: 8
    Latest: 23rd April 2006, 01:04 PM
  4. Problem When Hooking RS232 Through A Y-Adapter ?
    By iso9001 in forum General Electronics Chat
    Replies: 2
    Latest: 16th March 2005, 12:31 PM
  5. PIC Basic Plus and RS232 problem again. Help!!!
    By Beefer3 in forum Micro Controllers
    Replies: 1
    Latest: 15th November 2003, 12:08 AM

Tags for this Thread