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 support@ccsinfo.com

Problems with software and hardware uart in PIC18F4550

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



Joined: 16 Apr 2009
Posts: 18
Location: Spain

View user's profile Send private message

Problems with software and hardware uart in PIC18F4550
PostPosted: Thu Apr 16, 2009 8:28 am     Reply with quote

Hello everybody in this forum. I'm new in it, and this is my problem:

I'm using PIC18F4550 to communicate with a PC using a bluetooth device. This device communicates with the microcontroller via hardware uart. This communication works ok.
In the other hand I use a software uart in the pins used by ICSP (C6 & C7), this uart is useful in order to show info about the device itself (eg: if our supplier gives us a bluetooth module with a different firmware version, this will be checked by the PIC and will be shown via this interface...)
This software uart doesn't work, rubbish is received in the PC.

I thought that problem was in clock... but I use an external crystal at 8MHz.

In addition to the uart interfaces, I have an USB communication using the internal USB module in this PIC. The USB runs at 48MHz and works ok.

I think problem lies in the clock of the system but I configured it to get the clock directly from the external crystal not internal oscillator is used.

I configured all of them using the CCS compiler wizard and it generates this code:
Code:

#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES PLL2                     //Divide By 2(8MHz oscillator input)
#FUSES CPUDIV1                  //No System Clock Postscaler
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2

#use delay(clock = 8000000, CRYSTAL)
#use rs232(stream =WT11, baud=115200, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8)
#use rs232(stream = DEBUGG, baud= 9600, parity=N, xmit=PIN_B7, rcv=PIN_B6, bits=8)



In order to send data to each interface I use fprintf or fputc, using the correct stream (WT11 or DEBUGG).

I tried to solve the problem by setting the registers manually:

I create a variable in the memory position of the special function register...
Code:

//CONFIG1L y CONFIG1H -> Seleccionan el modo del oscilador y el postscaler y preescaler para el USB

#BYTE CONFIG1L      =0x300000
#BYTE CONFIG1H      =0x300001
#BYTE UCFG         =0xF6F
#BYTE OSCCON              =0xFD3

//CONFIG1L bits...
#BIT CONFIG1L_USBDIV   =0x300000.5   
#BIT CONFIG1L_CPUDIV1   =0x300000.4
#BIT CONFIG1L_CPUDIV0   =0x300000.3
#BIT CONFIG1L_PLLDIV2   =0x300000.2
#BIT CONFIG1L_PLLDIV1   =0x300000.1
#BIT CONFIG1L_PLLDIV0   =0x300000.0

//CONFIG1H bits...
#BIT CONFIG1H_IESO      =0x300001.7   
#BIT CONFIG1H_FCMEN      =0x300001.6
#BIT CONFIG1H_FOSC3      =0x300001.3
#BIT CONFIG1H_FOSC2      =0x300001.2
#BIT CONFIG1H_FOSC1      =0x300001.1
#BIT CONFIG1H_FOSC0      =0x300001.0


//UCFG bits...
#BIT UCFG_UTEYE      =0xF6F.7   
#BIT UCFG_UOEMON           =0xF6F.6
#BIT UCFG_UPUEN      =0xF6F.4
#BIT UCFG_UTRDIS           =0xF6F.3
#BIT UCFG_FSEN      =0xF6F.2
#BIT UCFG_PPB1      =0xF6F.1
#BIT UCFG_PPB0      =0xF6F.0


//OSCCON bits...
#BIT OSCCON_IDLEN      =0xFD3.7
#BIT OSCCON_IRCF2      =0xFD3.6
#BIT OSCCON_IRCF1      =0xFD3.5
#BIT OSCCON_IRCF0      =0xFD3.4
#BIT OSCCON_OSTS      =0xFD3.3
#BIT OSCCON_IOFS      =0xFD3.2
#BIT OSCCON_SCS1      =0xFD3.1
#BIT OSCCON_SCS0      =0xFD3.0




and now I configure each bit:
Code:


CONFIG1L_PLLDIV2 = FALSE;   // Prescaler selection bits
CONFIG1L_PLLDIV1 = 0;   // from 8MHz to 4MHz
CONFIG1L_PLLDIV0 = 1;

CONFIG1L_USBDIV   = 1;   //PLL at 96MHz
                  //96/2 --->  48MHz

UCFG_FSEN = 1;         //Full Speed USB

//---------------------------------------
//Configuración de reloj para CPU:
//---------------------------------------

CONFIG1L_CPUDIV1 =0;   //Primary osc. as the system clock
CONFIG1L_CPUDIV0 =0;

CONFIG1H_FOSC3 =1;      //CPU clock directly from crystal -> 8MHz
CONFIG1H_FOSC2 =1;      //HS without PLL
CONFIG1H_FOSC1 =0;
CONFIG1H_FOSC0 =0;      //This bit can be 0 or 1




But the compiler doesn't like it.... Can the configuration bits be accessed in this way??? It seems no.

Well this is my problem with software uart in this project...... any idea???

Thank you in advance¡¡¡¡¡ bye¡
bignick270



Joined: 11 Sep 2008
Posts: 44

View user's profile Send private message

PostPosted: Thu Apr 16, 2009 8:45 am     Reply with quote

I noticed when i used a hardware uart and a software uart at the same that on rare occasions when the hardware uart was receiving and the software uart was putting out data the timing would get messed up and the data going out the software uart was incorrect. I fixed that by adding a delay before the software uart could begin transmitting.

I am not saying this is your problem but it is something that I came across and only saw it by using a logic analyzer.
asmallri



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

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

PostPosted: Thu Apr 16, 2009 9:35 am     Reply with quote

You software uart timing is being affected by interrupts.
_________________
Regards, Andrew

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



Joined: 16 Apr 2009
Posts: 18
Location: Spain

View user's profile Send private message

Problem is now solved¡
PostPosted: Thu Apr 16, 2009 10:09 am     Reply with quote

Hello guys¡

I've solved the problem. The solution of the problem is to use a timer (eg: 100 us), so my time unit will be 100us. Next I send the info from the ISR using variables to control the transmition:

every second ---> send via software serial port next ...
send via hardware serial port and next...
send via USB interface...

well I don't understand why works in this manner but I will continue experimenting...

Bye and thank you very much¡¡
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