Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

[SOLVED] problems with sending frame via UART

Status
Not open for further replies.

treyz

Member level 5
Joined
Sep 26, 2012
Messages
93
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,065
Hi everyone,

I have a problem reading what is in my buffer.

I am sending a BIG frame: STX-DATA-CHECKSUM-ETX (1 byte each), from my PC to a PIC(18f4680) via RS232.

The things is, I am using a Blue LED to tell me if the buffer is filled in and a GREEN LED to tell me if the PIC can read the first byte which would be STX(0x02).
I can see the BLue LEd turns on but not the GReen Led. I have the right baud rate(9600 daud).
Do you have any idea of what might cause this issue?

I have attached my code.
 

Attachments


andre_teprom

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,198
Helped
1,142
Reputation
2,303
Reaction score
1,119
Trophy points
1,403
Location
Brazil
Activity points
53,521
Why don´t you echoes received data on PIC back to PC ?
This way you can debug each transferred byte.

+++
 

treyz

Member level 5
Joined
Sep 26, 2012
Messages
93
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,065
Hi,

Thanks for getting back to me

I have already written a code to test my RS232 connections,and it works fine with one char then I carried on my project changing just the type of data that I am sending and no changes.
here is my code for testing rs232
 

Attachments


Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
Are you able to send char like 'C' and do you want to send strings linke "Microcontroller" through UART?
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,579
Helped
4,778
Reputation
9,573
Reaction score
4,558
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
124,271
You seem to be reading the RCREG inside the interrupt routine and again in the main() routine, is this what you intended?

Brian.
 

andre_teprom

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,198
Helped
1,142
Reputation
2,303
Reaction score
1,119
Trophy points
1,403
Location
Brazil
Activity points
53,521
I still think that you must use UART to debug communication.
It is quite better to work.

You can even echoes received data, but also can attach another informations ( PIC counters, variables status, etc... ) :

Code:
STX-DATA-CHECKSUM-ETX-count#1-count#2-count#n-status#1-status#2-etc.....
+++
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
This is c code to send strings to UART. It assumes you have strlen() function in your compiler.

Code:
void UART_SendString(unsigned char UART_String[]);

void UART_SendString(unsigned char UART_String[]) {
	unsigned int i,j;

	j = strlen(UART_String);

	for(i=0;i<j;i++) {

		TXSTAbits.TXEN=0;// disable transmission
  		TXREG=UART_String[i];            // load txreg with data
  		TXSTAbits.TXEN=1;    // enable transmission
  		while(TXSTAbits.TRMT==0) // wait here till transmit complete
  		{
    			Nop();
  		}
	}
}
 

treyz

Member level 5
Joined
Sep 26, 2012
Messages
93
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,065
Hi,

Yes ,I am able to send 'C', I don't want to send a String, but few bytes via USART, the things is, it seems like it stays in the buffer. Could it be a timing issue?

Hi brian,

I am not using any interrupts, if you can see, I put interrupt in comments.

One more things,
I have used hyper terminal to test my RS232 communications but, for the rest of my project I am using another communication software(I can't display anything into it), I am just using to send my frame.

- - - Updated - - -

This is c code to send strings to UART. It assumes you have strlen() function in your compiler.


[/code]
I am using c18 compiler from mplab
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
what actually does your frame consist of. can you give an example of your frame?

Interrupts are not commented in RS232(good).txt

Which code are you using?

Did you try adding a small delay betwwen each character transfer to UART?
 
Last edited:

treyz

Member level 5
Joined
Sep 26, 2012
Messages
93
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,065
Yes sure,

I am receiveing a frame, wich contains Delimiters such as : <STX> and <ETX>. Between those two delimiters, I have my datas such as <data><checksum>.
Each of them is 1 byte.

That frame is sent from a PC(a software created by my manager) to a first PIC(18f14680) via RS23, then this PIC send that same frame to a second PIC via SPI. That second PIC(18f4680)will send the frame to a system via RS485.
All the way the frame will be the same, if the checksum is correct,if not, it will not do anything.

Did I make myself clear.....?
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
Yes, you made clear, but where actually is the problem occuring? at the 1st PIC or 2nd PIC? OK. I think the problem is at the first PIC.

Can I see the code you are using to send the frame?
 

treyz

Member level 5
Joined
Sep 26, 2012
Messages
93
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,065
what actually does your frame consist of. can you give an example of your frame?

Interrupts are not commented in RS232(good).txt

Which code are you using?

Did you try adding a small delay betwwen each character transfer to UART?
Example of my frame: 0x02 0x01 0x05 0x03
I decided to not use interrupt for my 1st PIC. The things is the data is sent from the PC,it is in a buffer but the 1st PIC doesn't seem to read it throught.
I have tried smaller delay,bigger delay, nothing works.

- - - Updated - - -

Can I see the code you are using to send the frame?[/QUOTE]

The code is in my first post. :)
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
is the baud rate parity and other things set properly on your PC side?

Do you think the problem is in usrt_gets() function? Where is ReadUSART(); function in the code? There is no ReadUSART(); definition.
 
Last edited:

treyz

Member level 5
Joined
Sep 26, 2012
Messages
93
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,065
No, the software that my manager created doesn't allow me to make those changes.
So I am guessing, I have just my code....

- - - Updated - - -

is the baud rate parity and other things set properly on your PC side?

Do you think the problem is in usrt_gets() function? Where is ReadUSART(); function in the code? There is no ReadUSART(); definition.
Sorry about that , I don't think you have noticed that few pieces of my code are commected out.
I have attached the same code without them
About ReadUSART(), it comes from the library of the UART from the c18 compiler.
 

Attachments

Last edited:

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
Sorry, I don't see the definition of ReadUSART(); function. Is it a library function?
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
OK. Your STX is 0x02 and ETX is 0x03, right? What is any other byte is 0x02 and 0x03 other than STX and ETX, what happens then?
 

treyz

Member level 5
Joined
Sep 26, 2012
Messages
93
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,065
OK. Your STX is 0x02 and ETX is 0x03, right? What is any other byte is 0x02 and 0x03 other than STX and ETX, what happens then?
Yes stx = 0x02 and etx= 0x03
then the all frame goes into the 1st PIC. This PIC analyzes the frame(performing a checksum and check to see whether or not data is in 8 bit), if everything is ok, then it can pass it on to the second PIC via SPI.
 

treyz

Member level 5
Joined
Sep 26, 2012
Messages
93
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,065

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top