News:

Let's find out together what makes a PIC Tick!

Main Menu

Changing BAUD rate

Started by joesaliba, Jul 08, 2022, 07:27 PM

Previous topic - Next topic

joesaliba

I would like to use an 16F1827 or 16F1847 which I have a few of these devices.

I would like to use two pins to use HRsin at different baud rates.

I have two devices I need to receive and send to. From one device I will be receiving and sending at 9600bps. From the other I will only receive at 38,400bps.

For the TX, I will set it to RB5 using the APFCON1.0 = 1.

However, for the receiving end I would like to alter the pin so I can use hardware USART by toggling the APFCON0.7.

Now my two questions: -

1. Will it work to alter the USART pin while PIC is running?
2. If yes, as I can only Declare HSerial_Baud once, what can I do to alter the baud rate when I change the pins?   

Regards

Joe

trastikata

Quote from: joesaliba on Jul 08, 2022, 07:27 PM1. Will it work to alter the USART pin while PIC is running?
2. If yes, as I can only Declare HSerial_Baud once, what can I do to alter the baud rate when I change the pins?   

1. Yes

2. Set up the Baud Rate generator registers manually - the formulas are available in the datasheet, and in addition there are on-line tools, that will do the register calculations for you. For example this here:
http://www.nicksoft.info/el/calc/?ac=spbrg


joesaliba

Quote from: Yasin on Jul 08, 2022, 08:52 PMhttps://protoncompiler.com/index.php/topic,924.msg7094.html#msg7094

I looked at all the declares in the manual but I missed this one Yasin.

Thank you all for your replies and help.

Regards

Joe

midali

I am interested in the subject . I didn't find a solution..

trastikata

#5
I don't see the problem here, simply change the Baud registers manually, to whatever value at whichever point you need it to change.

    BAUDCON1.3 = 1 '16-Bit Baud Rate Register Enable bit
    TXSTA1.2 = 0   'BRGH: High Baud Rate Select bit
    SPBRGH1 = 0   'EUSARTx Baud Rate Generator Register High Byte
    SPBRG1 = 25   'EUSARTx Baud Rate Generator Register Low Byte

Same goes for hardware I2C ... for example at 48MHz, switching between 400kHz to read/write to some memory and sensor ICs  and writing in I2C OLED at 1000kHz.

SSPADD = 29
...
SSPADD = 14

John Drew

I've changed hardware baud rates on the run by changing registers, very simple and works beautifully.
John

Dompie

Quote from: trastikata on Jul 09, 2022, 11:22 AMSame goes for hardware I2C ... for example at 48MHz, switching between 400kHz to read/write to some memory and sensor ICs  and writing in I2C OLED at 1000kHz.

Code Select Expand
SSPADD = 29
...
SSPADD = 14

Oh yeah, never thought of that

Johan