asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
-- serial receive error fix 18F46K22 - 26K22 pre A4 release |
Posted: Mon Mar 05, 2012 2:40 pm |
|
|
for the 18f46k22 26k22 family prior to rev A4
fix for 1 in 256 faulty character receive, silicon error
You can continue with the standard #useRS232 setup statement
BUT call this function BEFORE you do any serial transmit or receive
uartnum is 0 or 1 for the FIRST or second UART in these parts
masterfreq is the same value you use in the #use_delay() compiler directive
baudrate is YOUR desired baudrate
Code: |
void Set_baudfix( int1 uartnum, unsigned int32 masterfreq, unsigned int32 baudrate){
unsigned int16 baudiv;
// UART 1
#byte SPBRG =0xFAF
#byte SPBRGH=0xFB0
#byte TXSTA =0xFAC
#byte BAUDCON=0xFB8
#BIT BRG16 =0xFB8.3
// UART 2
#byte SPBRG2 =0xF75
#byte SPBRGH2=0xF76
#byte TXSTA2 =0xF72
#byte BAUDCON2=0xF70
#BIT BRG16_2 =0xF70.3
baudiv= (unsigned int16) (( masterfreq / (4*baudrate))-1);
if (!uartnum){
BRG16=1;
SPBRG =make8(baudiv,0);
spbrgh=make8(baudiv,1);
txsta=0xA6; // std 8 bit see txsta bit mapping and BRGH=1
// 0xA6 needs to be changed for 9 bits && other than 8-1-N
}
else{
BRG16_2=1;
SPBRG2 =make8(baudiv,0);
spbrgh2=make8(baudiv,1);
txsta2=0xA6; // std 8 bit see txsta bit mapping and BRGH=1
}
}
| [/code] |
|