Problem using Flex Full board and RS485 module

Forum related to the FLEX boards

Moderator: paolo.gai

cesiricerca
Newbie
Posts: 13
Joined: Wed Oct 29, 2008 1:49 pm

Problem using Flex Full board and RS485 module

Post by cesiricerca » Fri Apr 24, 2009 8:20 am

We are trying to use RS485 to communicate with an instrument. Our hardware is dsPIC Flex Full board (Flex003) and Flex Demo Daughter board (Flex109) with RS485 Module (Flex104) mounted on it.
We are able to correctly send data to the instrument, but we are not able to receive the answer from it. We verified that data are sent from the instrument (we receive signals on the UART2_RX pin) and we looped on the UART2 receive function to use a blocking mode. The 485 module has three jumpers: we used JP3 in position 2-3 (TX enabled) and JP2 in 2-3 (RX enabled) as described at link http://it.emcelettronica.com/flex.
Moving the jumpers in other positions the problem wasn\'t solved: if JP3 is in position 1-2 the trasmission doesn\'t work, while JP2 in position 1-2 nothing changes. Positioning JP1 nothing changes.
We encountered the same problems using the Flex+Multibus+485 instead of Flex+DemoDaughter+485.

We also tried using RS232, connecting the instrument via RS232 to RS485 converter (ADAM4520) and all worked fine.

Has someone used the Flex board with the RS485 serial interface ?

Thanks.

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re:Problem using Flex Full board and RS485 module

Post by paolo.gai » Mon Apr 27, 2009 3:50 pm

Hi!

About the RS485 being used: RS485 adapters similar to those of the FLEX has been used in production by our parnters in various industrial systems.

About the jumpers of the RS485 module:

JP3 on position 1-2 means that the TX must be enabled by the MCU
JP2 on position 1-2 means that the RX must be enabled by the MCU

that is, if JP2 and JP3 are on position 1-2, then the MCU controls the RX/TX mode by using the pin. if the pin is 1, then TX. If the pin is 0, then RX

if you put JP2 on position 2-3, reception is always enabled. That is, whatever you send you should also receive....

Ciao,

PJ

cesiricerca
Newbie
Posts: 13
Joined: Wed Oct 29, 2008 1:49 pm

Re:Problem using Flex Full board and RS485 module

Post by cesiricerca » Mon May 04, 2009 2:27 pm

We don\'t understand which pin we have to set using JP2 and JP3 in 1-2 position.
In UART2.h we found:
/* Set IO pins */
TRISFbits.TRISF4 = 1; // RX Pin
TRISFbits.TRISF5 = 0; // TX Pin
We tried to change the value but without success

Could you explain better how the MCU controls the RX/TX mode?

Ciao

GP

cesiricerca
Newbie
Posts: 13
Joined: Wed Oct 29, 2008 1:49 pm

Re:Problem using Flex Full board and RS485 module

Post by cesiricerca » Mon May 11, 2009 10:52 am

We tried the attached code, but we wasn\'t able to receive data.
The instrument replies correctly to the command, but no data on the UART2_Receive...
Thanks
Attachments

[The extension txt has been deactivated and can no longer be displayed.]


paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re:Problem using Flex Full board and RS485 module

Post by paolo.gai » Mon May 11, 2009 11:53 am

Hi,

Sorry for the delay in the answer.

--------------------

I\'m currently looking at the schematics of the RS485 module and of the multibus module. You should have a copy of them in the FLEX CDROM. If you do not have them, please send me a personal e-mail and I\'ll attach them to you.

The TXEN pin in the RS485 module is PIN 3 of the module.

if you used the first socket, then the pin3 is connected to SCK1 (which is PIN38 in CON6, which is RD15_PIN48 on the FLEX, which is connected to the pin RD15/IC8/U1RTS/CN21 of the dsPIC).

if you used the second socket, then the pin3 is connected to TXEN (which is PIN32 in CON6, which is RF13_PIN39 on the FLEX, which is connected to the pin RF13_U2RTS of the dsPIC).

That is, basically both TXEN are connected to the serial line RTS pins.

--------------------

From the dsPIC datasheet:

19.6 Flow Control Using UxCTS and
UxRTS Pins
UARTx Clear to Send (UxCTS) and Request to Send
(UxRTS) are the two hardware controlled active-low
pins that are associated with the UART module. These
two pins allow the UART to operate in Simplex and
Flow Control modes. They are implemented to control
the transmission and the reception between the Data
Terminal Equipment (DTE). The UEN bits in the
UxMODE register configures these pins.

The description of UEN is:

bit 9-8 UEN: UARTx Enable bits
11 =UxTX, UxRX and BCLK pins are enabled and used; UxCTS pin controlled by port latches
10 =UxTX, UxRX, UxCTS and UxRTS pins are enabled and used
01 =UxTX, UxRX and UxRTS pins are enabled and used; UxCTS pin controlled by port latches
00 =UxTX and UxRX pins are enabled and used; and UxRTS/BCLK pins controlled by
port latches

--------------------

That is, the UEN are on the UxMODE register, bit 8 and 9.

Everything depends on the value of UEN, and of the port latches if you decided to enable them. The code you posted is currently modifying U2STAbits.UTXEN!

Ciao,

PJ

cesiricerca
Newbie
Posts: 13
Joined: Wed Oct 29, 2008 1:49 pm

Re:Problem using Flex Full board and RS485 module

Post by cesiricerca » Tue May 12, 2009 10:01 am

could you send me the schematics of the RS485 module and multibus module?

ciao

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re:Problem using Flex Full board and RS485 module

Post by paolo.gai » Tue May 12, 2009 10:27 am

Ok, fine!

It\'s probably better to remove the e-mail from the post to avoid spam...

Paolo

cesiricerca
Newbie
Posts: 13
Joined: Wed Oct 29, 2008 1:49 pm

Re:Problem using Flex Full board and RS485 module

Post by cesiricerca » Mon May 18, 2009 2:49 pm

We performed some tests with the RS485 module using the multibus and daughter board.
The results are in the attached file.
The nodule works fine using the multibus board.
With the daughter board, the pin 3 (TXEN pin) of the module is never at high level and doesn\'t work.
The JMP 4,5,6 on the daughter board are in position 1-2,2-3,2-3.
From the schematics of the file \"demo_sch.pdf\", page 3 of 8, the RF13_pin39 is pin 5 of the 485; RF12_pin40 is pin 3 of 485 (that is TXEN). We found that setting PORTFbits.RF13, then the pin 5 of 485 is enabled. Setting PORTFbits.RF12, then the pin 3 of 485 is never enabled.
By soldering pin 5 to pin 3 of the RS485 module, all works fine with the demo daughter board!!
Perhaps we misunderstood someting??
Attachments

[The extension txt has been deactivated and can no longer be displayed.]


paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re:Problem using Flex Full board and RS485 module

Post by paolo.gai » Tue May 19, 2009 7:38 am

Hi,

I checked your text file with the report... i\'m going to put it into the Wiki for future reference.

The pins attached to PIN 3 in the multibus and demo daughter board are different because we needed the various pins for handling different features (the demo board basically uses all the pins and we tried hard to use all the pins in the best way. Unfortunately the pin for enabling RS485 in RX is not always the same.

From what i understand, you are reporting that RS485 works fine on the multibus board by programming the two pins of TXEN in case you are using slot1 or slot2 (which is what we expected), but you have still problems on the demo board.

The pin 3 of the RS485 module on the demo board is attached to RF12_PIN40_SCK1. But from your text file it seems you are moving 0/1 PORTFbits13 and not PORTFbits.RF12. Is that correct? Could you try moving PORTFbits.RF12?

About the image on http://www.evidence.eu.com/content/view/168/211/n ... you are right... UART1 and UART2 are inverted. We\'ll change it asap...

Thanks again!

PJ

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re:Problem using Flex Full board and RS485 module

Post by paolo.gai » Tue May 19, 2009 7:55 am

I just added a wiki page for future reference with the instructions on RS485.

Thanks,

PJ

cesiricerca
Newbie
Posts: 13
Joined: Wed Oct 29, 2008 1:49 pm

Re:Problem using Flex Full board and RS485 module

Post by cesiricerca » Tue May 19, 2009 8:13 am

Question:
The pin 3 of the RS485 module on the demo board is attached to RF12_PIN40_SCK1. But from your text file it seems you are moving 0/1 PORTFbits13 and not PORTFbits.RF12. Is that correct? Could you try moving PORTFbits.RF12?
Answer:
We tried to move 0/1 PORTFbits.RF12 as well (we forgot to mention it in our text file, sorry) but on pin 3 nothing happens (RX dosn\'t work, TXEN not enabled!).
ciao

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re: Problem using Flex Full board and RS485 module

Post by paolo.gai » Mon Apr 18, 2011 6:28 pm

Hi,

I'm currently out of town for a few days... without boards for doing the testing.

What you said in the first mail is correct.

About the second e-mail. Do you have a RS485-rs232 converter at hand? it may be useful for understanding if the problem you have is on the receiver side or on the transmitter side...

Cioa,

PJ

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re: Problem using Flex Full board and RS485 module

Post by paolo.gai » Tue Apr 19, 2011 7:46 am

Hi!

I'm happy you solved it...

Do you mind sharing two examples (transmitter and receiver), plus some comments on the setting / photo of the board configuration, so that we can include them in the kernel distribution as an example with your name?

This will help others to do the same experience you did...

Thanks!

PJ

moonckim
Newbie
Posts: 15
Joined: Fri Feb 04, 2011 9:18 pm

Re: Problem using Flex Full board and RS485 module

Post by moonckim » Tue Mar 20, 2012 11:44 pm

Following the instructions on the Wiki, I was able to send & receive bytes from one set of FLEX + Multibus daughter + RS485 to another set. Once tx of a packet is completed, the sender disabled TX interrupt inside the UART2 TX ISR (please see below for details). However, next time I re-enabled the TX INT (IEC1bits.U2TXIE = 1;), UART2 TX interrupt does NOT occur. Any thoughts? Is there any sample code for RS485 for switching between tx and rx?

RS485 on the second slot UART2.
Enable_UART2_TX() is called by application when a packet is ready.
UART2_TX_ISR() reads bytes from a buffer and transmits.
Inside UART2_TX_ISR(), if the buffer is empty (which means that the previous sent byte was the last one), it calls Disable_UART2_TX().

void Enable_UART2_TX()
{
PORTFbits.RF12 = 0;
PORTFbits.RF13 = 1; // TXEN enable TX

IEC1bits.U2TXIE = 1; // Enable Tx Interrupt
}

void Disable_UART2_TX()
{
PORTFbits.RF12 = 0;
PORTFbits.RF13 = 0; //TXEN disable TX

IEC1bits.U2TXIE = 0; // disable TX INT
}

moonckim
Newbie
Posts: 15
Joined: Fri Feb 04, 2011 9:18 pm

Re: Problem using Flex Full board and RS485 module

Post by moonckim » Tue Mar 20, 2012 11:46 pm

I fotgot one thing: The jumpers JP2 and JP3 on the RS485 adapters are set to pos 1-2 (TXEN).

Locked