• AVR Freaks

Hot!PIC32MZ and 4-20 mA T click

Author
msmiha
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2019/06/20 14:21:00
  • Location: 0
  • Status: offline
2019/09/29 06:08:55 (permalink)
0

PIC32MZ and 4-20 mA T click

Hi,
 
I'm trying to setup a 4-20 mA T click from MikroE and Curiosity PIC32MZ EF. I can not get output of more then 4mA regardless of what I set as an value. Bellow is a code:
 

// Control register values
#define CTRL_DACA 0x00
#define CTRL_UNBUFFERED 0x00
#define CTRL_BUFFERED 0x40
#define CTRL_GAIN_1X 0x20
#define CTRL_GAIN_2X 0x00
#define CTRL_ENABLED 0x10
#define CTRL_DISABLED 0x00
 
uint8_t APP_TX420mA_Write_Tasks(void)
{
    static APP_TX420mA_WR_STATES writestate = WR_SEND_WRITE_STATUS_CMD;
    uint32_t num_of_bytes;
    uint8_t ctrl_byte = CTRL_DACA | CTRL_UNBUFFERED | CTRL_GAIN_1X | CTRL_ENABLED;
    uint16_t value = 3800;

    switch(writestate)
    {
        case WR_SEND_WRITE_STATUS_CMD:
        {
            /* Assert CS Line */
            APP_SPI_CS_SELECT();

            /* Add Write status op code, data to the buffer */
            appData.SPITXbuffer[0] = ((uint8_t)(value >> 8) & 0x0F) | (ctrl_byte & 0xF0);
            appData.SPITXbuffer[1] = (uint8_t) (value & 0x00FF);

            /* Number of bytes to transfer */
            num_of_bytes = 2;

            /* Add to the write buffer and transmit*/
            APP_TX420mA_Write(&appData.SPITXbuffer[0], num_of_bytes);
            writestate = WR_WAIT_FOR_WRITE_COMPLETE;

            break;
        }
        case WR_WAIT_FOR_WRITE_COMPLETE:
        {
            /* Check if the transfer status is success or not */
            if(APP_TX420mA_Check_Transfer_Status(appData.Write_Buffer_Handle))
            {
                APP_SPI_CS_DESELECT();

                writestate = WR_COMPLETED;
            }
            else
            {
                /* Transfer Status - Wait untill staus becomes true*/
                writestate = WR_WAIT_FOR_WRITE_COMPLETE;
            }
            break;
        }
        case WR_COMPLETED:
        {
            /* return done to app task */
            writestate = WR_SEND_WRITE_STATUS_CMD;
            return true;
            break;
        }
        default:
            break;
    }
    return false;
}

 
Does anyone have a clue what am I doing wrong. I had build my project based on serial_eeprom example in Harmony v2.06. 
#1

0 Replies Related Threads

    Jump to:
    © 2020 APG vNext Commercial Version 4.5