| View previous topic :: View next topic |
| Author |
Message |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Mar 01, 2012 1:37 am |
|
|
| Quote: | | I assume when I do set_uart_speed, the compiler generates code that stops the uart and puts the new value |
It doesn't. The EUSART module basically allows to change the baud rate during operation. Of course, ongoing transmission or reception will be affected.
The restriction of set_uart_speed() to constant baud rate parameters has a rather trivial reason, the operation requires to put in the current clock speed according to the #delay statement in effect. It's simply a concession to user convenience. In addition, the function sets the related BRGH and BRG16 bits, which could be saved when just changing the value.
You most likely noticed, that set_uart_speed() is setting LSB first, while the CCS built-in 16-Bit access uses MSB first. The latter order is required for some 16-Bit registers like timers. According to the datasheet, it seems to be irrelevant for BRG accesses.
The CCS manual suggests to set alternative baudrates in a case structure. Obviously the solution doesn't serve all possible requirements. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20161
|
|
Posted: Thu Mar 01, 2012 9:53 am |
|
|
I think there is one other thing beyond the basic simplicity of restricting to a constant, which is that it allows the compiler to check for sensible rates. To actually code a universal function, you'd have to work out the switch points for different dividers, and once you have then calculated the divider and BRG value, then check the error percentage. A lot of work, and the function would then have to return an error flag to say that the requested rate is not achievable....
Best Wishes |
|
 |
maria100
Joined: 01 Feb 2012 Posts: 63
|
|
Posted: Thu Mar 01, 2012 3:51 pm |
|
|
| i done it...the main problem remains how quick the flash is gonna be killed....to many writes per second to the registers... |
|
 |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Mar 01, 2012 5:12 pm |
|
|
| You didn't yet mention anything like writing to flash, I dodn't see how it's related to the original problem. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9658 Location: Greensville,Ontario
|
|
Posted: Thu Mar 01, 2012 5:42 pm |
|
|
| and...now its about baudrate, which, if the yet unknown PIC has autobaud detection, can 'lock onto' the other device. If your PIC doesn't have that feature, uChip has information about writing your own 'autobaud' code. |
|
 |
|