|
|
View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 349
|
Hardware Uart in 9 bit mode [Solved] |
Posted: Thu Jul 27, 2017 2:29 pm |
|
|
Hello All,
I want to ask you if this is the right way to use hardware uart in 9 bit addressing mode.
Example:
Code: |
#use rs232(baud=9600,rcv=PIN_C7,xmit=PIN_C6,bits=9,ERRORS,stream=B485)
#bit ninth_bit = RS232_ERRORS.7
byte TestPacket[] = {0x07, 0x01, 0x01, 0x00, 0x08, 0x1A, 0x00, 0x2B};
void SendDataToB(int8 *data, int8 len){
int8 i;
for(i = 0; i < len; i++){
if(i == 0)
ninth_bit=1;
else
ninth_bit=0;
fputc(data[i], B485); // Send data
}
} |
I'm sending an example "TestPacket" but the device is not responding.
What could be the problem?
Thanks for attention!
Last edited by kmp84 on Thu Jul 27, 2017 3:01 pm; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Thu Jul 27, 2017 2:34 pm |
|
|
You don't have to.
Assuming a reasonably modern compiler, when set to 9bit mode, the getc, and putc instructions will accept a 16bit value, and handle the extra bit automatically (the functions are 'overloaded', and if they see a 16bit value, switch operation to handle this). |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Jul 27, 2017 2:44 pm |
|
|
I have a question...
You have 'stream=B485' in the USE RS232(...options...)
To me, that implies you're using an RS485 transceiver. If so, you also need to declare the 'control' pin for the TXX/RXD of the RS485 device. Unless it being used ONLY for one direction of data.
Also, if RS485 is being used, you need to use the correct pullup/pull down and termination resistors. These will be detailed in the RS485 device datasheet.
Jay |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 349
|
|
Posted: Thu Jul 27, 2017 2:46 pm |
|
|
Hi Mr.Ttelmah,
How to handle 9 bit? Some example please?
Thanks, |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 349
|
|
Posted: Thu Jul 27, 2017 2:55 pm |
|
|
temtronic wrote: | I have a question...
You have 'stream=B485' in the USE RS232(...options...)
To me , that implies you're using an RS485 transceiver. If so, you also need to declare the 'control' pin for the TXX/RXD of the RS485 device. Unless it being used ONLY for one direction of data.
Also, if RS485 is being used, you need to use the correct pullup/pull down and termination resistors. These will be detailed in teh RS485 device datasheet.
Jay |
At the moment I'm using rs232 , but hardware also has and rs485 with this settings :
Code: |
#use rs232(baud=9600,rcv=PIN_C7,xmit=PIN_C6,enable=pin_B2,bits=9,ERRORS,stream=B485) |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Jul 27, 2017 5:22 pm |
|
|
OK... what does the device use for communications? RS232 or RS485 ?? There is a BIG difference in the hardware AND then there's the software side to consider.
You cannot just connect a PIC up directly to the 'device', you need the correct interface chip(s).
If the 'device' is a commercial product, provide a link to the datasheet. That will help us.
'Not working' could be you've got a bare PIC tied to the device, you have TXD and RXD swapped, missing ground between devices, MAX232 tied to MAX485, and that's just a start of possibles....
Happy to help but I need more details about the project.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 27, 2017 7:37 pm |
|
|
Quote: | I want to ask you if this is the right way to use hardware uart in 9 bit addressing mode. |
CCS gives examples of how to do this in the RS485.c file, in the drivers folder.
UART setup:
Code: | #use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=9, long_data, errors, stream=RS485) |
Look at this function in the RS485.c file:
Code: | int1 rs485_send_message(unsigned int8 to, unsigned int8 len, unsigned int8* data) {
.
.
.
} |
|
|
|
kmp84
Joined: 02 Feb 2010 Posts: 349
|
Problem Solved |
Posted: Tue Aug 15, 2017 4:13 pm |
|
|
Hello All,
Sorry for my delayed response. I did not have for a long time PC and internet connection.
I have made successful communication in "9 bit long_data" format with hardware uart and also with software uart over physical rs232 and rs485.
Thank you very much ! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|