• AVR Freaks

Hot!DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue

Author
Anniyanx
Starting Member
  • Total Posts : 39
  • Reward points : 0
  • Joined: 2006/11/06 21:25:37
  • Location: 0
  • Status: offline
2020/02/26 23:01:23 (permalink)
0

DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue

Hi this topic might not be directly related to microchip issue,but anyway im using a DSPIC33EP interfaced with
PmodRS485 (powered up using 3.3v,pic16 explorer board) to communicate to a labtop serial port (DtechRS485 to USB converter). im using realterm to monitor the data transmission and reception.
 
Im sending a packet as below:-
BE A0 12 34 02 10 00 02 00 00 00 5B C3 00 89 B1
 
but i always receive it on realterm as :
00 BE A0 12 34 02 10 00 02 00 00 00 5B C3 00 89 B1
 
At first i thought is it a firmware issue,but after testing with "UART to USB converter" i can receive the same packet, so it is only when im using rs485 to usb converter.
 
so the issue is, an extra byte 0x00 received in beginning of the transmission, i read few forums and realized that this is to do with the fail-safe receiver input of the rs485 driver, meaning if i encounter this problem using the any RS485 chips, we need bias the differential line so that it will not be floating during no TX driver activation.
 
as per that i added a 940ohms resistor from the A to the +3.3v, and B to the GND, as im using full duplex, did the same on the other differential line Z-pulled to gnd, and Y pull up to 3.3v using 940ohms.
 
anyway this didnt solve the issue,i still get the extra 0x00 at the beginning.
 
my question is can we use one side of the master rs485 powered using 3.3v and the slave side chip is 5v (anyway i assume the Dtech rs485 to usb is powered by 5v from USB port). Will this cause the issue as above.
what else can be problem,i believe it is a hardware issue and not any firmware problem as uart to usb transmission works fine.
 
the pmodrs485 schematics:-
https://reference.digilentinc.com/_media/reference/pmod/pmodrs485/pmodrs485_sch.pdf
 
 
thanks....
#1

16 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3477
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/27 05:08:55 (permalink)
    0
    Supplies of 5 V resp. 3.3 V should not be an issue.
    Might be a firmware issue, either receiving a long break as 0x00 or even transmitting 0x00 following the driver enable signal.
    BUT:
    If you have a full-duplex point-to-point communications link implemented, why do you fiddle with driver enable at all?
    Set the driver enable once and let the transceiver enabled !

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    ric
    Super Member
    • Total Posts : 26159
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/27 15:02:48 (permalink)
    0
    I suspect du00000001 is right.
    You never explain how you are driving the DE and RE signals, or show any of your PIC code.
    I would assume if you left both the transmitter and receiver permanently enabled, you wouldn't see the extra byte.
     
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    Anniyanx
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2006/11/06 21:25:37
    • Location: 0
    • Status: offline
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/27 17:59:17 (permalink)
    0
    du00000001
    Supplies of 5 V resp. 3.3 V should not be an issue.
    Might be a firmware issue, either receiving a long break as 0x00 or even transmitting 0x00 following the driver enable signal.
    BUT:
    If you have a full-duplex point-to-point communications link implemented, why do you fiddle with driver enable at all?
    Set the driver enable once and let the transceiver enabled !


     
    i never turn on and off the driver enabled, during initialization, i enabled both TX and RX and leave them enabled all the time. i dont get the 0x00 if i sent using a UART-USB converter, but only get i when use RS485-USB converter (Dtech brand).
     
    im using a DSPIC33EP512MU810 MCC generated usart interrupt code with the buffer managements.
     
    my pin initialization code:-
        //control for PMODRS485 at JA interface
        ANSELG = 0;
        TRISGbits.TRISG9 = 0;
        TRISGbits.TRISG6 = 0;
        
        LATGbits.LATG9 = 0;// P14 => ~RE drive low-> enable rx -> enable receiver for 485
        LATGbits.LATG6 = 1;// P10 => DE drive enable line high -> enable transmitter for 485
        
        LATGbits.LATG8 = 1; // follow mcc comment at UART init
      //LATGbits.LATG9 =
            
        //as PMODRR485 is not directly compatible, PPS is rewired to use
        //the available PMOD JA interface
        __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS
           RPOR14 = 0;
           RPOR14bits.RP120R = 1; //RP120/RG8 -P12,PIN2@pmod => TXD
           RPINR18bits.U1RXR = 119; //RPI119/RG7 -P11,PIN3@pmod => RXD
         __builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS*/
        //------------------------------------------------------------

     
    My transmit code is as below:-
    uint8_t SINGLESHOT_TX_FRAME_BE (void) 
     {
     uint8_t writeBuffer[16];
     unsigned short CRC16value;
     uint8_t CRC16LSB;
     uint8_t CRC16MSB;
     
     writeBuffer[0]=0xBE; //sycn writeBuffer[1]=0xA0; //sync
     writeBuffer[1]=0xA0; //sync
     writeBuffer[2]=0x12; //sync
     writeBuffer[3]=0x34; //sync
     writeBuffer[4]=0x02; //sync-ver
     writeBuffer[5]=0x10; //datalength
     writeBuffer[6]=0x00; //datalength 0x0010 => 16
     writeBuffer[7]=0x02; // verification method-CRC16 2 for crc16
     writeBuffer[8]=0x00; //future
     writeBuffer[9]=0x00; //future
     writeBuffer[10]=0x00;//future
     writeBuffer[11]=0x5B;//cmd
     writeBuffer[12]=0xC3;//cmd
     writeBuffer[13]=0x00; //0:singleshot ,1:continues
     writeBuffer[14]=0x00;
     writeBuffer[15]=0x00;

                 
     //calculate the CRC
    int writebufferLen = sizeof(writeBuffer);
     
    CRC16value = CRC16(writeBuffer,(writebufferLen-2));

    CRC16LSB = (uint8_t)(CRC16value & 0x00FF);
    CRC16MSB = (uint8_t)(CRC16value >> 8);

     writeBuffer[14]=CRC16LSB;
     writeBuffer[15]=CRC16MSB;
     
    unsigned int numBytes = 0;

       while(numBytes < writebufferLen)
       {
        numBytes += UART1_WriteBuffer (writeBuffer+numBytes, writebufferLen); // if wana send exact len
       }
      
       while(UART1_IsTxDone()) // txtail=txhead, reached last byte and wait it tx
       {
            // Wait for the tranmission to complete
       }
      return(numBytes);
     }

     
    i just tried a simply code 
    U1TXREG=0xff;

    also will display as 0x00 0xFF, but what i find out is if i continuously send the transmits frame twice (one after another), only the the first frame have the 0x00 [frame], and the next frame is ok, looks like only first time have the 0x00.
    #4
    Anniyanx
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2006/11/06 21:25:37
    • Location: 0
    • Status: offline
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/27 18:03:53 (permalink)
    0
    ric
    I suspect du00000001 is right.
    You never explain how you are driving the DE and RE signals, or show any of your PIC code.
    I would assume if you left both the transmitter and receiver permanently enabled, you wouldn't see the extra byte.
     
     
     


      Yup i enabled it both, and the routine is called before the UART initialization.
     
       
     //control for PMODRS485 at JA interface
        ANSELG = 0;
        TRISGbits.TRISG9 = 0;
        TRISGbits.TRISG6 = 0;
        
        LATGbits.LATG9 = 0;// P14 => ~RE drive low-> enable rx -> enable receiver for 485
        LATGbits.LATG6 = 1;// P10 => DE drive enable line high -> enable transmitter for 485
        
    p i enabled both TX and RX in the initialization as below:-
     
     
     
     
    post edited by Anniyanx - 2020/02/27 18:11:31
    #5
    ric
    Super Member
    • Total Posts : 26159
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/27 18:09:18 (permalink)
    0
    Are you doing this first transmit immediately after initialisation, or long after?
    To avoid glitches, the init code should set the LATx registers before the TRISx registers.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    Anniyanx
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2006/11/06 21:25:37
    • Location: 0
    • Status: offline
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/27 19:06:38 (permalink)
    0
    ric
    Are you doing this first transmit immediately after initialisation, or long after?
    To avoid glitches, the init code should set the LATx registers before the TRISx registers.
     


    im not exactly transmitting after initialization,there is some small delay of executing other codes. 
    i change the initialization sequenced as your suggestion, and tested a simple 
     
    U1TXREG=0xff;
    U1TXREG=0xff;
     
    and i still received in terminal as 00FFFF, anyway my BAUDRATE is 921600.  i changed the sequence as below:
     
      //MY routines Set PPS for JA interface for rs458 direction control--
        //control for PMODRS485 at JA interface
        //ANSELG = 0;
        LATGbits.LATG9 = 0;// P14 => ~RE drive low-> enable rx -> enable receiver for 485
        LATGbits.LATG6 = 1;// P10 => DE drive enable line high -> enable transmitter for 485
       
        LATGbits.LATG8 = 1; // TXD pin,just follow mcc warning for UART init
        LATGbits.LATG7 = 0; // RXD
        
        TRISGbits.TRISG9 = 0; //for RE
        TRISGbits.TRISG6 = 0; // for DE
        TRISGbits.TRISG8 = 1; //TXDpin uart
        TRISGbits.TRISG7 = 1;//RXDpin uart
        ANSELG = 0;
            
        //as PMODRR485 is not directly compatible, PPS is rewired to use the available PMOD JA interface

        __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS
           RPOR14 = 0;
           RPOR14bits.RP120R = 1; //RP120/RG8 -P12,PIN2@pmod => TXD
           RPINR18bits.U1RXR = 119; //RPI119/RG7 -P11,PIN3@pmod => RXD
         __builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS*/
        //------------------------------------------------------------

     
    previously i started the whole code using MCC generations but because some mistake in the port pin selection, i write the above code to reinitialize the UART pin and the PPS and also the RS485 RE and DE port.  i just put the code below the PIN_MANAGER_Initialize(); 
     
    as u said i set LATG then TRISG , and then ANSELG and finally the PPS code. i still get the first transmission as 0x00.
     
     
    #7
    ric
    Super Member
    • Total Posts : 26159
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/27 19:37:56 (permalink)
    0
    Have you actually looked at the signals with a scope?
    I still have a suspicion you're seeing a glitch caused by the startup code.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    Anniyanx
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2006/11/06 21:25:37
    • Location: 0
    • Status: offline
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/28 00:47:09 (permalink)
    0
    ric
    Have you actually looked at the signals with a scope?
    I still have a suspicion you're seeing a glitch caused by the startup code.
     


    for time being i have no access no a scope, will have soon.....will try and update this issue.
    #9
    du00000001
    Just Some Member
    • Total Posts : 3477
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/28 02:11:36 (permalink)
    0
    This additional 0x00 byte is only received once following the initialiation?
    Attribute that to the Dtech adapter, discard it and proceed.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #10
    ric
    Super Member
    • Total Posts : 26159
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/28 02:21:07 (permalink)
    0
    the byte, or the Dtech adapter? ;)
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #11
    du00000001
    Just Some Member
    • Total Posts : 3477
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/28 02:29:34 (permalink)
    0
    ric
    the byte, or the Dtech adapter? ;)



    His choice  :)

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #12
    Jerry Messina
    Super Member
    • Total Posts : 468
    • Reward points : 0
    • Joined: 2003/11/07 12:35:12
    • Status: offline
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/02/28 07:22:53 (permalink)
    5 (1)
    Try initializing the DE pin high AFTER initializing the UART so that the transmitter is disabled until after the TXD pin is idle (high). If DE is high before the TXD pin is high that would likely produce the 00 byte.
     
    The PMOD has a pulldown on DE so it will be disabled until the DE is set and your failsafe bias should keep the Y-Z outputs in the idle state.
     
    #13
    Anniyanx
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2006/11/06 21:25:37
    • Location: 0
    • Status: offline
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/03/02 17:36:03 (permalink)
    0
    du00000001
    This additional 0x00 byte is only received once following the initialiation?
    Attribute that to the Dtech adapter, discard it and proceed.


    yup only the first time, if i send two consecutive byte as below
     
    U1TXREG=0xFF; U1TXREG=0xFF; .............. => il get : 00FFFF
     
    and if im using different adaptor, which is a only UART to USB converter, then i dont get the zero in erminal.




    post edited by Anniyanx - 2020/03/02 17:42:44
    #14
    ric
    Super Member
    • Total Posts : 26159
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/03/02 18:30:00 (permalink)
    0
    Haven't got access to a scope yet?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #15
    Anniyanx
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2006/11/06 21:25:37
    • Location: 0
    • Status: offline
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/03/02 23:42:31 (permalink)
    0
    ric
    Haven't got access to a scope yet?
     



    nope,not yet....so as for now im leaving it as it is....and will update this later on, also as for now i  can communicate with the actual sensor with the host "DSPIC and its firmware" and the sensor can responds to it after getting the commands which i transmit to it using the PmodRS485 as the interface....
     
    #16
    du00000001
    Just Some Member
    • Total Posts : 3477
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: DSPIC33EP interfaced with PmodRS485 (ADM2582E) connection issue 2020/03/03 08:58:55 (permalink)
    0
    The additional 0x00 is received on the PC side ?
    Do you switch-on the dsPIC with the PmodRS485 interface already attached ?
    Might be an artefact from switching-on. Discarding the first character received (provided it's 0x00) shouldn't really be too difficult.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #17
    Jump to:
    © 2020 APG vNext Commercial Version 4.5