This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using RS-422 based absolute encoder with InstaSPIN

Other Parts Discussed in Thread: MOTORWARE

Hi,

I am trying to interface with a RS-422 UART based absolute encoder in the sensored InstaSPIN project. The encoder sends a packet of 8 bytes, which contains 3 byte absolute position data and other status and configuration bits.

I based my code on examples provided here. However, I found many issues, such as missing functions in pie and sci headers. E.g, PIE_registerPieIntHandler, PIE_enableInt, SCI_setRxFifoIntLevel. I defined those functions based on the C2000_LaunchPad libraries. Here is the rest of my code: 7242.enc_comm.zip  This is my interrupt service routine:

interrupt void sciaRxFifoIsr(void)
{

ENC_COMM_updatePosition(encCommHandle);

// Clear Overflow flag
SCI_clearRxFifoOvf(ENC_COMM_getSciHandle(encCommHandle));

// Clear Interrupt flag
SCI_clearRxFifoInt(ENC_COMM_getSciHandle(encCommHandle));

// Issue PIE acknowledgment
PIE_clearInt(DRV_getPieHandle(drvHandle), PIE_GroupNumber_9);

return;
}

I am able to send commands to the encoder to start and stop transmission and it seems to respond well. However, I am not able to read the received data properly. I was assuming that the word size in F28069M is 16 bits, so a 4 word fifo interrupt would let me receive the 8 byte data. But, the received data in the buffer seems to be of 8 bits. The interrupt doesn't seem to be firing at the correct time. Is there something that I am missing? Will I have to configure the module differently to achieve what I am trying to achieve? 

I would really appreciate any help. 

Thanks,

Tamil 

  • Tamil,

    The functions you claim are missing are all included in MotorWare, please download the latest version (_09).

     

  • Chris,

    I am using the _09 version of Motorware. I found the functions I mentioned in the include files for f2802x, not f2806x. I am using F28069M microcontroller.  

    Nevertheless, I managed to port the functions, and I am able to communicate with the encoder. My encoder sends out 8 bytes of data in every packet, but it seems that the Rx FIFO buffer can handle only a maximum of 4 bytes. Is this correct? Is there a way to handle 8 bytes?

    Thanks,
    Tamil

  • Tamil, I do see some differences between the 02x and 06x version of the SCI.

    I'm going to file a bug to get the 6x drivers update w/ respect to the 2x.

     

  • Thanks.

    What is the maximum number of of bytes that can be received using the SCI FIFO buffers? 

    -Tamil

  • per the SCI user's guide there are 4 Transmit and 4 receive buffers, each a byte.

     

  • The user guide mentions that the buffers can have up to 4 words. The variables used to represent Rx/Tx registers were uint16_t, so I assumed the buffers were 16 bits wide each. Thanks for the clarification.

    -Tamil

  • Hello Tamil,

    Did you solve your problem?

    How about using non-FIFO SCI? Have you tried it?

    I can get data per byte continuously using non-FIFO SCI and put it in the buffer before I parse it for my purpose but in this case I need to enable the RX interrupt.

    However, I think this will help you to get 8 bytes data and put it in the buffer before you parse it.

    Best regards,

    Maria

  • Hi Maria, 

    Thanks for your suggestion.

    Yes, I managed to come up with something that works. 

    I ended up using the FIFO, which lets me get 4 bytes at a time. Luckily, the data that I read comes with a constant header and footer, so I can easily identify which is the first half and which is the second half. Based on that I process my data.

    Regards,
    Tamil

  • Hey Tamil,

    Do you have some example code for how you are using the serial port? I was able to use Maria's suggestions to compile one of the FOC examples (lab05b) to use the SCI port. Right after the HAL_init() function I put a for loop that is writing to the serial port:

      for (;;) {
        SCI_write(halHandle->sciaHandle, 'k');
        SCI_putDataNonBlocking(halHandle->sciaHandle, 'k');
        SCI_putDataBlocking(halHandle->sciaHandle, 'k');
      }

    However the LED for the TX pin does not light up and I am not getting any data over serial. I am able to compile and run the Example_F2802xSci_Echoback program but this is not using Motorware.

    Also, maybe it is possible to use the JTAG directly for communications with an external program (I'm trying to send / receive data from a python program), maybe it would be easier to use JTAG for this? Maybe it would be dangerous to use JTAG since it could potentially corrupt the flash?