Hi All,
I had an example from Richard lately where he configured my 16F18446 HW serial's port.
I didn't pay that much attention to it...
Now that I'm looking closer on "how he did it", I can't figure it out.
So I went to "visit" the DS and after lots of calculations and trials, I'm still stuck.
This is an extract from Richard's code (as said from another thread/project), the piece of code I'm working on.
Code:' ====== PIC 16F18446 FUSES ======================================================================= ' Internal oscillator #CONFIG __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON __config _CONFIG2, _MCLRE_ON & _PWRTS_PWRT_64 & _LPBOREN_OFF & _BOREN_SBOREN & _BORV_LO & _ZCDDIS_OFF & _PPS1WAY_OFF & _STVREN_ON __config _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTD_OFF & _WRTSAF_OFF & _LVP_OFF __config _CONFIG5, _CP_OFF #ENDCONFIG @ ERRORLEVEL -306 @ ERRORLEVEL -202 ' ====== DEFINES / REGISTERS ====================================================================== DEFINE OSC 32 DEFINE ADC_BITS 12 'Number of bits in ADCIN result DEFINE HSER_TXSTA 24h 'Enable transmit, BRGH = 1 DEFINE HSER_CLROERR 1 'Clear overflow automatically BAUDCON.3 = 1 'Enable 16 bit baudrate generator ' Baudrates @ 32MHz ' 9600 'DEFINE HSER_SPBRG 832 'SP1BRGH = 51 ' 19200 ''DEFINE HSER_SPBRG 416 'SP1BRGH = 25 ' 57600 'DEFINE HSER_SPBRG 138 SP1BRGH = 0 ' 115200 'DEFINE HSER_SPBRG 68 'SP1BRGH = 0 ' ====== VARIABLES ================================================================================ RC3PPS = 15 'TX PORTC.3 - set RC3 to EUSART TX ' ====== TEST PROGRAM ============================================================================= HW_SERIAL: HSerout ["Hello World!",13,10] HSerout ["Testing...",13,10] PAUSE 1000 GOTO HW_SERIAL:
While the settings for baudrates 57600 and 115200 work perfectly, I can't make it work for slower baudrates like 19200 or even 9600.
I tried to follow the DS and, even if in Richard's example some values don't chage like for instance the SP1BRGH on, I thought I should use the following formula.
It doesn't work.
But looking at the baudrate examples table, I can't find the difference for all proposed baudrates.
Can anyone please explain whre I'm missing the point (or points)?


Reply With Quote

Bookmarks