I’m busy with a networking project between PIC micro controllers using RS485. I designed my own protocol initially, but it does not have the flexibility I now need.
I then decided to use USART . I had a look at Nigels tutorials, (Tutorial 7) and worked through them all to see what will suit me best. If anyone’s ever done this before, you will know that only Tutorial 7.7 covers USART.
While running the MPLAB SIM I keep an eye out on the stopwatch to see how long these routines take to execute. With Nigel’s code the baud rate is set at 9600. This equates to about ~100us per bit. For 10 bits that then adds up to ~1ms. (This is with the Rcv_RS232 routine).
When running the transmit routine (XMIT_RS232) it takes about 2us. The question is now, how long does it take the data that’s now been stored in the TXREG to be serially transmitted out?
If I use the following method (see code below), monitoring the TXIF bit of register PIR1, it takes about 8ms for the transmit routine to finish. This is obviously not right? (8ms for 10 bits, is about 1200 BAUD).
For my networking application I need to know when the TXREG has successfully been transmitted as I need to move on to the next node. Waiting 8ms is hopelessly to long for me.
Can anybody please explain what’s happening here? Surely the TX routine should also take about 1ms for a total of 10 bits to be sent (1 Start, 8 Data, 1 Stop bit)?
I then decided to use USART . I had a look at Nigels tutorials, (Tutorial 7) and worked through them all to see what will suit me best. If anyone’s ever done this before, you will know that only Tutorial 7.7 covers USART.
While running the MPLAB SIM I keep an eye out on the stopwatch to see how long these routines take to execute. With Nigel’s code the baud rate is set at 9600. This equates to about ~100us per bit. For 10 bits that then adds up to ~1ms. (This is with the Rcv_RS232 routine).
When running the transmit routine (XMIT_RS232) it takes about 2us. The question is now, how long does it take the data that’s now been stored in the TXREG to be serially transmitted out?
If I use the following method (see code below), monitoring the TXIF bit of register PIR1, it takes about 8ms for the transmit routine to finish. This is obviously not right? (8ms for 10 bits, is about 1200 BAUD).
Code:
TXRS232: movwf TXREG ; send data in W
bsf STATUS,RP0 ; RAM PAGE 1
WtHere btfss TXSTA,TRMT ; TXSTA<1>. Transmit Shift Register status bit
goto WtHere ; Transmission is complete if hi
BRK bcf STATUS,RP0 ; RAM PAGE 0
Return
For my networking application I need to know when the TXREG has successfully been transmitted as I need to move on to the next node. Waiting 8ms is hopelessly to long for me.
Can anybody please explain what’s happening here? Surely the TX routine should also take about 1ms for a total of 10 bits to be sent (1 Start, 8 Data, 1 Stop bit)?