subspacedarkspace
Electrical
- Jul 10, 2006
- 8
Hi,
I am using PIC16F876A to relay data from RS-485 devices multi-drop daisy chain configuration (one master – multiple slaves) by means of Asynchronous serial module to a processing unit by means of I2C bus module.
Hardware Configurations:
RS-485 chip PIC16F876A
------------- -------------
Ro ------> RC7
DI ------> RC6
DE ------> RC5
RE' ------> RC5
My communication protocol is one master will always be in transmitting mode and the slaves will be in receiving mode. Slaves are only allowed to transmit when they are polled by the master. Otherwise the slaves have to be listening to master all the time.
When the microcontroller starts for the first time, RC5 is initialized to 1. After every issued poll, I clear RC2 so that I can enable receiver and start receiving data from targeted slave device. Unfortunately, RC5 refuses to go low, the line stays high, and I can not receive any data.
The following is the main code that the PIC16F876A will keep executing all the time:
==============================================================
while(TRUE) // Create an infinite loop
{
RS_485_crc_CALC(sData, 3); // Calculate the crc value for the outgoing poll command
sData[2] = (255 - crcValue); // append the calculated crc value to the end of outgoing poll command
RC5 = 1; // Enter transmittion mode :: Enable Tx Driver and Disable Rx receiver.
for (count1 = 0; count1 < 3 ; count1++) // loop :: this is the length of outgoing poll command.
{
putchar(sData[count1]); // Transmit one character at time.
}
RC5 = 0; // Enter receiving mode :: Enable Rx Receiver and Disable Tx transmitter
getchar(&c); // Get first incoming character
sendBuffer[5] = c; // Append first character to I2C Data array buffer
getchar(&c); // Get Second incoming character
sendBuffer[6] = c; // Append second character to I2C data array buffer
getchar(&c); // get third incoming character
sendBuffer[7] = c; // Append third character to I2C data array buffer
// Heart beat indicator to indicate that the pic is reaching this line.
if (!LEDTime) // Check TIMER1 counter
{
RA4 = (RA4 == FALSE); // Toggle the LED
LEDTime = TIMER1_LED_DELAY; // Restart TIMER 1
}
// Reset the PIC watch dog, tipical time is 18ms before automatic reset from memory location 0x00000
CLRWDT();
}
Please, can you help. This is getting very criticle as I am falling behind my schedule because of this issue.
I am using PIC16F876A to relay data from RS-485 devices multi-drop daisy chain configuration (one master – multiple slaves) by means of Asynchronous serial module to a processing unit by means of I2C bus module.
Hardware Configurations:
RS-485 chip PIC16F876A
------------- -------------
Ro ------> RC7
DI ------> RC6
DE ------> RC5
RE' ------> RC5
My communication protocol is one master will always be in transmitting mode and the slaves will be in receiving mode. Slaves are only allowed to transmit when they are polled by the master. Otherwise the slaves have to be listening to master all the time.
When the microcontroller starts for the first time, RC5 is initialized to 1. After every issued poll, I clear RC2 so that I can enable receiver and start receiving data from targeted slave device. Unfortunately, RC5 refuses to go low, the line stays high, and I can not receive any data.
The following is the main code that the PIC16F876A will keep executing all the time:
==============================================================
while(TRUE) // Create an infinite loop
{
RS_485_crc_CALC(sData, 3); // Calculate the crc value for the outgoing poll command
sData[2] = (255 - crcValue); // append the calculated crc value to the end of outgoing poll command
RC5 = 1; // Enter transmittion mode :: Enable Tx Driver and Disable Rx receiver.
for (count1 = 0; count1 < 3 ; count1++) // loop :: this is the length of outgoing poll command.
{
putchar(sData[count1]); // Transmit one character at time.
}
RC5 = 0; // Enter receiving mode :: Enable Rx Receiver and Disable Tx transmitter
getchar(&c); // Get first incoming character
sendBuffer[5] = c; // Append first character to I2C Data array buffer
getchar(&c); // Get Second incoming character
sendBuffer[6] = c; // Append second character to I2C data array buffer
getchar(&c); // get third incoming character
sendBuffer[7] = c; // Append third character to I2C data array buffer
// Heart beat indicator to indicate that the pic is reaching this line.
if (!LEDTime) // Check TIMER1 counter
{
RA4 = (RA4 == FALSE); // Toggle the LED
LEDTime = TIMER1_LED_DELAY; // Restart TIMER 1
}
// Reset the PIC watch dog, tipical time is 18ms before automatic reset from memory location 0x00000
CLRWDT();
}
Please, can you help. This is getting very criticle as I am falling behind my schedule because of this issue.