![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
gilavar
Joined: 03 Mar 2009 Posts: 24
|
Strange HW UART problem with PIC24FJ32. Please HELP! |
Posted: Wed Jun 17, 2009 12:15 pm |
|
|
I am not very good at programming, but have to solve this problem ASAP, so any help will be appreciated.
When I am using soft RS232 then everything works just fine. When I am using hardware UART1, then data in U(x)RXREG shifted left one bit adding zero to LSB. I tried all possible U(x)MODE settings including Simplex mode without any success. Has anyone had this problem before?
My settings are:
PCWHD rev 4.083, PIC24FJ32, clock=32000000,
Code: |
#pin_select U2TX=PIN_B12
#pin_select U2RX=PIN_B11
#pin_select U2RTS=PIN_B14
#pin_select U2CTS=PIN_B13
//#use rs232(baud=9600,xmit=PIN_B12,rcv=PIN_B11,parity=N,bits=8,stop=1,ERRORS, stream=PC)
//Works great!
|
Code: | #use rs232(UART2,baud=9600,parity=N,bits=8,ERRORS,disable_ints,stream=PC)
// Buffer shifted left one bit with 0 at LSB |
|
|
![](templates/subSilver/images/spacer.gif) |
gilavar
Joined: 03 Mar 2009 Posts: 24
|
Strange solution... |
Posted: Thu Jun 18, 2009 1:50 pm |
|
|
I tested 2400bps with the same results and assumed that at this low rate internal OSC error can’t be any more then RS232 tolerance. UxBRG was calculated correct. Simple IO switching measured around 300 PPM frequency error, acceptable for UART. Only when I calculated UxBRG value to 9500 with 9600bps set to the host(Checked with several PCs), my communication started to work error free. Ten out of Ten PICs giving me the same result and Microchip do not have any errata on this issue. My question to PIC gurus: Am I missing something or this is common with PIC24 series? Should I test it with PICs from another supplier before releasing this design? |
|
![](templates/subSilver/images/spacer.gif) |
gilavar
Joined: 03 Mar 2009 Posts: 24
|
Re: Strange solution... |
Posted: Sun Jun 21, 2009 11:13 am |
|
|
Well, I used “Auto baud rate detection” feature of this controller and it looks like it takes care of this problem. But in general I do not understand how 10 different controllers can be so consistent on OSC frequency offset. It is hard to determine in my monologue if this is common issue with this controllers or not. |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Jun 21, 2009 2:10 pm |
|
|
I would prefer a complete minimal test application that allows to reproduce the problem. It would also clarify the exact chip type and #fuses settings, yet unknown. |
|
![](templates/subSilver/images/spacer.gif) |
gilavar
Joined: 03 Mar 2009 Posts: 24
|
|
Posted: Sun Jun 21, 2009 3:14 pm |
|
|
Thank you for trying to help me with this.
MCU is: PIC24FJ32GA004. Application is very large, but here is what I used for rs232 settings:
Code: |
#include <24FJ32GA004.h>
#device ICD=TRUE
#device ADC=10
#WORD CLKDIV = 0x744
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICS3 //ICD communication channel 3
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
//#FUSES IOL1WAY
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
//#FUSES IESO //Internal External Switch Over mode disabled
#FUSES FRC_PLL //Internal Fast RC oscillator with PLL
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES OSCIO //OSC2 is IO output
#FUSES NOPR //No Primary Oscillator
#FUSES I2C1SELD
#use delay(clock=32000000)
// this is from forum
#byte RPINR20L = 0x6A8
#bit IOLOCK = 0x742.6
#byte OSCCONL = 0x742 |
Code: |
#BYTE U2RXREG = 0X0236
#BYTE U2RXREG2 = 0X0237
#BYTE U1MODE = 0X0220
#BYTE U1MODE2 = 0X0221
#BYTE RCON = 0X0740
#BYTE U1BRG = 0X0228
#BYTE U1BRG2 = 0X0229
#BYTE U1STA = 0x0222
#BYTE U1STA2 = 0x0223
#BIT ABAUD = 0X0230.5
#define RTS = PIN_B13
#pin_select OC1=PIN_B2
#pin_select SCK1OUT=PIN_B8
//#pin_select SDI1=PIN_B9
#pin_select SDO1=PIN_B10
#pin_select SS1OUT=PIN_B6
#pin_select U1TX=PIN_B12
#pin_select U1RX=PIN_B11
#pin_select U1RTS=PIN_B14
#pin_select U1CTS=PIN_B13
unsigned int16 Vsns;
unsigned int16 Isns;
unsigned int8 CHG_current;
unsigned int8 CHG_LED_count;
extern int1 BAT_err; //batery error flag
extern int16 just;
extern unsigned int16 CHG_timer1; //Total Charge timer in Seconds
extern unsigned int16 CHG_timer2; //Charge Cycle timer in Seconds
unsigned int8 CHG_status; /* Charger status. 0=No battery, 1=Battery Detected, 2=Conditioning,
3=charging, 4=Top-Off, 5=Charge Complete, 9=Battery Error */
void Init()
{
// this is from forum
OSCCONL = 0x46;
OSCCONL = 0x57;
IOLOCK = 0;
RPINR20L = 0xFF09; // SPI1 Data Input = RP9 - PIN_RB9
OSCCONL = 0x46;
OSCCONL = 0x57;
IOLOCK = 1;
/******************************************************/
CLKDIV = 0;
//#use rs232(baud=9600,xmit=PIN_B12,rcv=PIN_B11,parity=N,bits=8,stop=1,ERRORS, stream=PC)
#use rs232(UART1,parity=N,bits=8,ERRORS,stream=PC)
U1MODE = 0x20; //Enable Auto baud rate
U1MODE2 = 0x80;
U1BRG = 0;
U1BRG2 = 0;
//#use SPI(SPI1, baud=115200, BITS=8)
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1,255 );
setup_compare(1,COMPARE_PWM | COMPARE_TIMER2 );
set_pwm_duty(1,0);
setup_wdt(WDT_OFF);
setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
//setup_timer2(TMR_DISABLED |TMR_DIV_BY_1 ,0);
//setup_timer4(TMR_DISABLED |TMR_DIV_BY_1 ,0);
setup_timer3(TMR_INTERNAL |TMR_DIV_BY_256,3110); //6225
//setup_timer5(TMR_INTERNAL |TMR_DIV_BY_256 ,62499);
setup_adc_ports(sAN5 | sAN6 | sAN11, VREF_VREF);
setup_adc(ADC_CLOCK_DIV_4);
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
setup_spi2(SPI_SS_DISABLED);
/*********** INTERRUPTS ****************************/
//enable_interrupts(INTR_GLOBAL);
//enable_interrupts(INT_EXT0);
//enable_interrupts(INT_SPI1);
enable_interrupts(INT_RDA);
//enable_interrupts(INT_TBE);
//enable_interrupts(INT_CNI);
//enable_interrupts(INT_CRC);
//enable_interrupts(INTR_CN_PIN|Pin_A4);
enable_interrupts(int_timer3);
//enable_interrupts(int_timer5);
|
In INT_RDA I am using fgetc(PC) and fputc. |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Jun 21, 2009 4:54 pm |
|
|
I didn't yet realize, that you use the internal oscillator. It seems most likely to me, that the problems are related to FRC accuracy. How did you verify the internal oscillator frequency? I didn't use the internal oscillator with PIC24F, but according to the specification, the accuracy is rather poor.
The best way, to check the UART timing directly would be a precise measurement of TX waveforms. |
|
![](templates/subSilver/images/spacer.gif) |
gilavar
Joined: 03 Mar 2009 Posts: 24
|
|
Posted: Sun Jun 21, 2009 8:42 pm |
|
|
I do have a very stable com over the soft RS232. I am not very good at C and tested OSC frequency using asm's bset&bclr over the nop with all the interrupts off. Frequency is very accurate on all ten units. I scoped the Com's using 0x55, and outgoing clock is way off where Soft module giving out very accurate clock.
FvM wrote: | I didn't yet realize, that you use the internal oscillator. It seems most likely to me, that the problems are related to FRC accuracy. How did you verify the internal oscillator frequency? I didn't use the internal oscillator with PIC24F, but according to the specification, the accuracy is rather poor.
The best way, to check the UART timing directly would be a precise measurement of TX waveforms. |
|
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Jun 21, 2009 11:58 pm |
|
|
Yes, when the software UART works correct, you can expect that the oscillator frequency is basically O.K.
I found, that with clock=32000000 the baud generator is initialized somewhat strange by the PCD built-in function. BRGH is set to 1 (high speed mode), although the baud rate can be achieved in normal mode as well. I wonder if that can be the reason for the problems. I don't know however, if V4.083 is using the same settings, also you didn't show your code without autobaud.
You can set U1MODE=0x8000 and U1BRG=0x0067 manually and check, if you get a different behaviour. |
|
![](templates/subSilver/images/spacer.gif) |
gilavar
Joined: 03 Mar 2009 Posts: 24
|
|
Posted: Mon Jun 22, 2009 1:21 pm |
|
|
FvM wrote: | Yes, when the software UART works correct, you can expect that the oscillator frequency is basically O.K.
I found, that with clock=32000000 the baud generator is initialized somewhat strange by the PCD built-in function. BRGH is set to 1 (high speed mode), although the baud rate can be achieved in normal mode as well. I wonder if that can be the reason for the problems. I don't know however, if V4.083 is using the same settings, also you didn't show your code without autobaud.
You can set U1MODE=0x8000 and U1BRG=0x0067 manually and check, if you get a different behaviour. |
Yes, V4.083 setting-up UART with BRGH high at 32Mhz. I tried both modes with U1MODE=0x8000 and U1MODE=0x8008(U1MODE2 @ 0X0221) but no luck. Unfortunately I will have to give-up on research and move forward with this project using auto-baud. So far it works very good. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
gilavar
Joined: 03 Mar 2009 Posts: 24
|
|
Posted: Mon Jun 22, 2009 2:07 pm |
|
|
Thank you PCM programmer, I used these errata notes to set-up auto-baud configuration. But I did not found anything about clock error with preset baud rate with or without BRGH. Again, my internal OSC running within +/-500PPM to the reference and Soft module working just fine. Very soon I will have to implement boot-loader to this application and I do not know if this may cause any problem. For sure this forum will be my only hope. |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jun 22, 2009 4:31 pm |
|
|
I tried your code with a 24FJ128GA010 and it has correct serial output.
Thus I think it's most likely a device specific issue. |
|
![](templates/subSilver/images/spacer.gif) |
gilavar
Joined: 03 Mar 2009 Posts: 24
|
|
Posted: Mon Jun 22, 2009 4:43 pm |
|
|
FvM wrote: | I tried your code with a 24FJ128GA010 and it has correct serial output.
Thus I think it's most likely a device specific issue. |
Thank you for doing it. In this case I better order another set of controllers with the different date code and test it one more time. Just in case if it was a problem with the single wafer or lot. I will post an update. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|