Continue to Site

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.

  • 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.

rs232 problem

Status
Not open for further replies.

tss

New Member
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);
}
 
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:
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 ?
 
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)?
 
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 ?
 

Attachments

  • Doc1.doc
    108.5 KB · Views: 210
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.
 
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.
 
  • Like
Reactions: tss
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
}
 
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
 
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.:)
 
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.
 
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.
 
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.. https://www.electro-tech-online.com/threads/rf-module-interface-with-pic.35474/

Also here is a chip that does the job and can be used on both ends. https://www.rfmodules.com.au/rm/products/ctr124.htm
 
Last edited:
unsigned short i;

void main() {

// Initialize USART module (8 bit, 19200 baud rate, no parity bit..)
Usart_Init(19200);

do {
if (Usart_Data_Ready()) { // If data is received
i = Usart_Read(); // Read the received data
Usart_Write(i); // Send data via USART
}
} while (1);
}//~!

i used program above to test serial port with hyperterminal. it suppose to be like i press 'a' from the keyboard then usart_read will read 'a' and usart_write will send character 'a' back and show 'a' in hyperterminal but it doenst work when i try. what is the problem ?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top