View previous topic :: View next topic |
Author |
Message |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
There's a way to avoid the automatic configuration of RCSTA? |
Posted: Wed Mar 23, 2016 2:06 pm |
|
|
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
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
|
|
Posted: Wed Mar 23, 2016 2:29 pm |
|
|
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
|
|
Posted: Thu Mar 24, 2016 9:14 am |
|
|
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
|
|
Posted: Thu Mar 24, 2016 9:46 am |
|
|
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. |
|
|
|