CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

-- serial receive error fix 18F46K22 - 26K22 pre A4 release

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

-- serial receive error fix 18F46K22 - 26K22 pre A4 release
PostPosted: Mon Mar 05, 2012 2:40 pm     Reply with quote

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]
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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