PDA

View Full Version : 2 Pics, different baud rates needed



peter_wiersig
- 18th February 2010, 20:19
We have
1 PIC18F2550
1 PIC18F2423

Config 2550

@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _BORV_3_2L & _VREGEN_ON_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
@ __CONFIG _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
@ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
@ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
@ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
@ __CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
@ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
@ __CONFIG _CONFIG7H, _EBTRB_OFF_7H
DEFINE OSC 20
DEFINE CHAR_PACING 1000
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 2400
DEFINE HSER_CLROERR 1


Config 2423

@ __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_OFF_2L & _BORV_1_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_1_2H
@ __CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_PORTC_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
@ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
@ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
@ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
@ __CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
@ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
@ __CONFIG _CONFIG7H, _EBTRB_OFF_7H
DEFINE OSC 20
DEFINE CHAR_PACING 1000
DEFINE DEBUG_REG PORTC
DEFINE DEBUG_BIT 6
DEFINE DEBUG_BAUD 19200
DEFINE DEBUG_PACING 100
DEFINE DEBUGIN_REG PORTC
DEFINE DEBUGIN_BIT 7
DEFINE SER2_BITS 8
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 6000
DEFINE HSER_CLROERR 1


Code Example:


preprogramloop:
IF OtherPICconnected THEN ' check a I/O-pin
'PAUSE 50
HSERIN 1000, preprogramloop, [WAIT("#"), STR SeriellBuffer\2]
IF SeriellBuffer[0] = "X" AND SeriellBuffer[1] = "X" THEN
HSEROUT ["@OK"]
GOTO Docked
ENDIF
GOTO preprogramloop
ENDIF


We measured the 2550 + 2423 TX lines with an oscilloscope until we found a HSER_BAUD rate that matched and we got no problem communicating between those two PICs.

Does it make any sense that those two HSER_BAUD settings differ?

mackrackit
- 18th February 2010, 21:40
What do you have for an external OSC on the 2550?
I doubt it is running at 20MHz. Maybe 48?

peter_wiersig
- 18th February 2010, 22:00
No, it really definitly is running on 20 Mhz,

Fuse PLLDIV_5_1L provides internal 4MHz which is used to to drive the 96Mhz internal PLL which gets divided to 48Mhz for USB via _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L. Fuse _FOSC_HSPLL_HS_1H should select the right frequency for the MCU promary clock.
DS39632E-page 31 & schema on DS39632E-page 24

Have no PBP at home, only able to access the source. If you have access to the PBP libs and lookup the PBP config fuses, it should show that a 20 MHz OSC could work.

USB communication is no problem, the 2400 baud on 2550 is seen on oscilloscope IIRC. (now at home - at friday night or saturday able to clock it again).

Thanks for the fast reply.

peter_wiersig
- 27th February 2010, 15:51
We have
1 PIC18F2550
1 PIC18F2423

Config 2550

@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
...
DEFINE OSC 20


We measured the 2550 + 2423 TX lines with an oscilloscope until we found a HSER_BAUD rate that matched and we got no problem communicating between those two PICs.

Does it make any sense that those two HSER_BAUD settings differ?

Those fuses let the 2550 run at 48 MHz, we coded a sample program and measured again with our oscilloscope


DebugLoop:
TOGGLE PORTC.1
PAUSE 100
GOTO DebugLoop

Which showed a ~40 ms pulse on the 2550 and a 100 ms pulse on the 2423, from there it was back to the data sheets and we found our error.

config 2550

@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
DEFINE OSC 20