Hi Carlos,
If you stay with a fixed buss frequency there is only so many baudrates you can achieve and many of these will be non-standard.
I have created a table that lists all of the possible baudrates for buss frequencies of 8MHz and for 7.3728MHz
, ,8000000,7372800
64, , 125000, 115200
1, 1, 125000, 115200
1, 2, 62500, 57600
1, 4, 31250, 28800
1, 8, 15625, 14400
1, 16, 7813, 7200
1, 32, 3906, 3600
1, 64, 1953, 1800
1,128, 977, 900
3, 1, 41667, 38400
3, 2, 20833, 19200
3, 4, 10417, 9600
3, 8, 5208, 4800
3, 16, 2604, 2400
3, 32, 1302, 1200
3, 64, 651, 600
3,128, 326, 300
4, 1, 31250, 28800
4, 2, 15625, 14400
4, 4, 7813, 7200
4, 8, 3906, 3600
4, 16, 1953, 1800
4, 32, 977, 900
4, 64, 488, 450
4,128, 244, 225
13, 1, 9615, 8862
13, 2, 4808, 4431
13, 4, 2404, 2215
13, 8, 1202, 1108
13, 16, 601, 554
13, 32, 300, 277
13, 64, 150, 138
13,128, 75, 69
I have highlighted all the standard baudrates
As I said before you can try and calculate it if you like but by the time you round it off and indicate the ones you can't acheive etc you will be better off with a simple switch statement.
int init_sci(baud){
switch (baud){
case 115200:
SCBR = 0x00;
break;
case 57600;
SCBR = 0x01;
etc
default:
return -1;
}
return 0;
}
BR Peg
Message Edited by peg on 04-16-200610:57 AM