View previous topic :: View next topic |
Author |
Message |
sit
Joined: 21 Jul 2023 Posts: 3
|
Undefined identifier TXSTAbits , RCSTAbits |
Posted: Sat Jul 22, 2023 4:03 am |
|
|
How to solve this error (16F685)?
Code: |
// Function to initialize UART module
void UART_Init() {
output_low(PIN_C7); // TX pin as output
output_high(PIN_C6); // RX pin as input
TXSTAbits.TXEN = 1; // Enable transmitter
RCSTAbits.CREN = 1; // Enable receiver
TXSTAbits.BRGH = 1; // High-speed mode
}
|
Thank you |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9168 Location: Greensville,Ontario
|
|
Posted: Sat Jul 22, 2023 5:09 am |
|
|
curious am i , so downloaded the datasheet.
According to Table3, on page 4, that PIC does NOT have a UART. That explains the error message.
The version 689 and 690 do have the USART though.
BTW, these...comments are wrong.
output_low(PIN_C7); // TX pin as output
//configures the pin as an output and sends a 'zero' to that pin
output_high(PIN_C6); // RX pin as input
//configures the pin as an output and sends a 'one' to that pin |
|
![](templates/subSilver/images/spacer.gif) |
sit
Joined: 21 Jul 2023 Posts: 3
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9168 Location: Greensville,Ontario
|
|
Posted: Sat Jul 22, 2023 10:32 am |
|
|
Yes, it should be possible, though you'll need to use a 'software' UART. The device is NOT 'RS-485', rather just normal TTL, so you connect PIC TX pin to module RX pin, and PIC RX pin to modules TX pin.
You'll also have to create the 'CRC', that they talk about..it's the last 2 bytes the PIC will send. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Sat Jul 22, 2023 11:38 pm |
|
|
It'll be hard though. The whole approach will need to be re-thought, since
receive on a software UART has no buffering and requires you to be
waiting for the data. It can probably be done, but will need a lot of
reprogramming. I must admit the idea of handling serial MODBUS without
a serial interrupt is going to be pretty scary programming. |
|
![](templates/subSilver/images/spacer.gif) |
sit
Joined: 21 Jul 2023 Posts: 3
|
|
Posted: Sun Jul 23, 2023 6:03 am |
|
|
Ttelmah wrote: | It'll be hard though. The whole approach will need to be re-thought, since
receive on a software UART has no buffering and requires you to be
waiting for the data. It can probably be done, but will need a lot of
reprogramming. I must admit the idea of handling serial MODBUS without
a serial interrupt is going to be pretty scary programming. |
By using the PIC 16F685 microcontroller to interface with the PZEM-004T module and requesting data only when necessary, I can avoid the continuous need for serial communication and data reading, which eliminates the need for complex buffering mechanisms and real-time handling. This approach allows I to have more control over when data is retrieved, making it easier to handle the communication process and ensuring that I ready to receive and process the data when it is requested.
Do you agree?
Best regard |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9168 Location: Greensville,Ontario
|
|
Posted: Sun Jul 23, 2023 7:37 am |
|
|
Provided you use one of the 10 pins that are 'IOC', you can create a reliable software UART. 'Old school', done before UARTs were actually available.
I'm pretty sure someone here , or on the Internet, has cut code...... |
|
![](templates/subSilver/images/spacer.gif) |
|