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

There's a way to avoid the automatic configuration of RCSTA?

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



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

There's a way to avoid the automatic configuration of RCSTA?
PostPosted: Wed Mar 23, 2016 2:06 pm     Reply with quote

I have a PIC18F67J50 that uses both USARTs and I'm having an issue regarding the ports, usually USART1, the issue is that the TX goes permanently to low state and RX seems to be deaf.

Unfortunately I could not reproduce the problem while I'm been debugging.

I read in the errata that before you enable SPEN bit all the port must be set and that bit must bit set alone and after enable that bit must wait two Tcy before execute any other instruction.

I analyze the generated asm and the compiler is setting RCSTA1 by issuing
Code:

MOVLW 0x90
MOVWF 0xfac,ACCESS


..at init code part that is not accessible from C, I mean I can't put ASM instructions because is between
Code:

void main (void)


and the first C instruction.

I'm using two streams, one for GSM and one for GPS, and I need to keep those streams.

Compiler version is 5.025
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Wed Mar 23, 2016 2:29 pm     Reply with quote

The way to do this is to use the trick outlined just a couple of threads ago. You can tell #USE RS232 to not actually turn on the UART. A 10 second search will find how to do this.

Then use a #BIT command to access the SPEN bit, and for the NOP's use 'delay_cycles(1);'.

So your enable code would become
Code:

SPEN=TRUE;
delay_cycles(1);
delay_cycles(1);


This will code as a bit_set for the SPEN bit, and two NOP's.

However you don't need this.
Re-read the erratum.


It only applies if _interrupts are enabled_.

Interrupts are not enabled at the start of the code.

It also only applies if the following instruction is a 'two cycle instruction'. So a call or goto etc..

If you are re-configuring the UARTs inside the code, then temporarily disable interrupts while you do this. Otherwise this is not your problem.

You _do_ have 'ERRORS' in your UART setup lines?. Otherwise an error might cause a problem. You must have ERRORS, unless _you_ handle errors yourself.
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Thu Mar 24, 2016 9:14 am     Reply with quote

So, let see if understand well, I cant set both streams and tell to the compiler that configure all in the USARTs, even the bps speed without turn in on them?

The program is a bit complex, it have 3 different power states so it uses 3 different clocks and the USARTs works only in the fastest one so I deactivate them in the other 2 power states.
Also the USART2 (GPS) start at 115200bps and then change to 19200bps.

I have code that make all that inside and outside the interrupts routines.


About ERRORS flags I'm handling in the ISR of each USART before read RCREG.

Today is a holiday for Easter until next Monday so I have not the code here.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Thu Mar 24, 2016 9:46 am     Reply with quote

Having you talk about doing such changes inside and outside the interrupts, introduces the worry of what happens if an interrupt occurs in the middle of the changes?.
Visualise: You change the baud rate, and in the middle of the change an interrupt occurs. This then changes the baud rate, and returns. The remainder of the external change then occurs. Result incorrect configuration...

The compiler will protect you if you use a 'common' routine to do this, by disabling interrupts around the outside version. However simple things like port accesses have no such protection. You need to do this yourself.

I'd be very suspicious that an incorrect mix of changes to the UART, is your problem.
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