CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

full duplex uart problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

full duplex uart problem
PostPosted: Mon Aug 26, 2013 8:52 am     Reply with quote

hi.

I want to use usart serial interface for transmit and receive data between pic18f87j11 with 50mhz clock speed and dspic33fj256mc710 with 80mhz clock speed with probee ze10 rf module and 9600 baudrate, but I have a problem.




my connection is synchronous until when i use a delay in while().


how can i have a connection, without error and Synchronous with rx and tx pin?


Can i use RDA interrupt for receive data?

When i use getc() in while(1) and i use a delay, the connection lost and connection not synchronous.

Can i use a timer to putc and getc function?

Thanks

v4.130
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Aug 26, 2013 10:58 am     Reply with quote

show your code.
and BTW are you using wireless ISM type transceivers ??
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Mon Aug 26, 2013 12:37 pm     Reply with quote

Basic thing.
EX_SISR.C

EX_STISR.C

You need to remember that the PIC only has a tiny amount of hardware buffering on the UART.
If you stop reading characters (or writing new ones to send), while you delay, communications will stop. Incoming data will be lost, and outgoing transmissions will stop.

The same is true on the PC (though most modern UART's have quite large buffers). Solution is interrupt driven comms (exactly what the PC does).
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Aug 26, 2013 4:21 pm     Reply with quote

to add to what Mr. T has said,
if there is a cheap ISM link in the picture, then
you will need to adopt some method of dc restoration and perhaps send 0x55 or 0xCC as filler chars to prevent character distortion in the received
data stream.

those pics of potential ISM cards are scary that way.

Very Happy Very Happy
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 4:20 am     Reply with quote

asmboy wrote:
to add to what Mr. T has said,
if there is a cheap ISM link in the picture,


Well, they appear to be Zigbee modules running off 3.3V. The PIC18F87J11 is also 3.3V capable so that's good. However its only capable of running up to 48MHz, so 50MHz is not good: may work sometimes, or with some chips, or when its cool, or... well, you shouldn't run them at 50MHz and expect them to work reliably.

As others have said, circular buffered, interrupt driven serial IO is without doubt the way to go. Its standard systems programming stuff, has been since the early sixties. To be honest had I been CCS I'd have built it into the compiler as a serial interface option long ago.
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 4:42 am     Reply with quote

I'm glad they finally added it (buffered interrupt driven serial) to the compiler as well.
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 11:08 am     Reply with quote

when i connect 2 18f pic series the uart work but when i connect dspic & 18f its not work and the connection not synchronous..

Please see the files below ....

receive code :

Code:
#include <33fj32mc204.h>
#FUSES PR                       //Primary Oscillator
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES EC                       //External clock with CLKOUT
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOJTAG                   //JTAG disabled
#use delay(clock=40m) //high clock speed for this chip
#include <LCD.C>
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
int test;
void main()
{
lcd_init();
while(true){
if (kbhit()){
test=getc();}
lcd_gotoxy(1,1);
printf(lcd_putc,"%u",test);
}
}




transmit code:


Code:
#include <18f87k22.h>
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES ECH_IO                   //External clock ,high power
#FUSES NOPLLEN                  //4X HW PLL disabled, 4X PLL enabled in software
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#use delay(clock=48m)
#use rs232(UART1,baud=9600,parity=N,bits=8,errors)
int test=12;
void main()
{
while(true){
putc(test);
}
}




So it seems that the uart connection between 18f and dspic not synchronous and have problem

please download isis file and test it with above code

http://www.up2www.com/uploads/1377623243121.zip

thanks
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Aug 27, 2013 12:09 pm     Reply with quote

There is no need to download and test. If is obvious from you code you have used an UART receive interrupt handler and, as a consequence, it is no surprise that you have problems.

Use an interrupt driven receive ring buffer and your problem will go away.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 12:12 pm     Reply with quote

Your problem is that you are not using the UART.....

The DsPIC's, have _relocatable_ peripherals. These have to be setup.
You need to use:

Code:

#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7
#use rs232(baud=9600,parity=N,UART1,bits=8,errors)


Which tells the compiler to connect UART1, to pins C6, and C7, and then use this. Just using the pins in #use rs232, results in a software UART being implemented, so the data will be missed while you are writing to the LCD....

Best Wishes
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 1:24 pm     Reply with quote

Ttelmah wrote:
Your problem is that you are not using the UART.....

The DsPIC's, have _relocatable_ peripherals. These have to be setup.
You need to use:

Code:

#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7
#use rs232(baud=9600,parity=N,UART1,bits=8,errors)


Which tells the compiler to connect UART1, to pins C6, and C7, and then use this. Just using the pins in #use rs232, results in a software UART being implemented, so the data will be missed while you are writing to the LCD....

Best Wishes


thanks for your answer

but this my code

Code:
#include <33fj32mc204.h>
#FUSES PR                       //Primary Oscillator
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES EC                       //External clock with CLKOUT
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOJTAG                   //JTAG disabled
#use delay(clock=40m) //high clock speed for this chip
#include <LCD.C>
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)


i use uart and define the xmit and rcv pin in dspic chip.

this dspic chip (33fj32mc204) not have hardware uart that i can use it

i test your code but its not work

Code:
#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7
#use rs232(baud=9600,parity=N,UART1,bits=8,errors)
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 3:30 pm     Reply with quote

Mahdi wrote:

this dspic chip (33fj32mc204) not have hardware uart that i can use it


According to the chip data sheet, it has 1 hardware UART and it is located on peripheral pins (as noted above by another poster).
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 5:10 pm     Reply with quote

jeremiah wrote:
Mahdi wrote:

this dspic chip (33fj32mc204) not have hardware uart that i can use it


According to the chip data sheet, it has 1 hardware UART and it is located on peripheral pins (as noted above by another poster).



when i use 4800 baud in receiver the data is clear and the connection is synchronous.


Code:
#include <33fj32mc204.h>
#FUSES PR                       //Primary Oscillator
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES EC                       //External clock with CLKOUT
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOJTAG                   //JTAG disabled
#use delay(clock=40m)
#include <LCD.C>
#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7
#use rs232(baud=4800,parity=N,UART1,bits=8,errors)



I do not know what to do anymore!!
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 5:27 pm     Reply with quote

As previously posted ....
"Use an interrupt driven receive ring buffer and your problem will go away." by Andrew

Have a look at the example 'ex_sisr.c' in the examples folder to see how to use a ring buffer

You _must_ use an ISR with buffer to get any reliable high speed serial data transfers .

I can get 115K200 using this method...so I know it works!

hth
jay
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Wed Aug 28, 2013 6:29 am     Reply with quote

temtronic wrote:
As previously posted ....
"Use an interrupt driven receive ring buffer and your problem will go away." by Andrew

Have a look at the example 'ex_sisr.c' in the examples folder to see how to use a ring buffer

You _must_ use an ISR with buffer to get any reliable high speed serial data transfers .

I can get 115K200 using this method...so I know it works!

hth
jay



can you explain me about ring buffer and the ex_sisr.c and stisr.c well, i dont know about buffer on pic chip

thanks alot
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Wed Aug 28, 2013 7:34 am     Reply with quote

Seriously, nothing to do with the PIC....

This is basic standard programming.

Do a Google search on 'ring buffer'.

The whole point is that the PIC, only has a couple of characters of hardware buffering. It only takes a moment, to overflow these. It however (in common with just about every other chip), has the ability to tell you:
1) When a character has been received.
2) When a character can be sent.

These two events trigger 'interrupts', which can call code.

When '1' happens, you simply receive the character, and write it to the buffer. When you want to see if anything has been received, you look at the buffer, not the UART.

When you want to send data you write it to another buffer, and enable the interrupt on event '2'. The data is then sent automatically from the buffer to the UART as space becomes available in the hardware.

Just about _every_ piece of code on the market today, that sends/receives data from any computer, uses such buffers. The PC etc. etc..

Nothing to do with the PIC at all.

CCS gives examples of such a buffer for transmit, and for receive. Look at them.

With V5, there is also an option to generate such buffers automatically.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group