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.

TMAG5170-Q1: TMAG5170

Part Number: TMAG5170-Q1
Other Parts Discussed in Thread: TMAG5170, ADS1262, ADS1220

Hi.

Do you have some sample C code to read / write a register of TMAG5170?
32-bit frame does not allow using standard options using libraries SPI.

Regards,

Alexandr

  • Alexander,

    Thank you for your question. Presently we don't have any source C code available.  We can notify you once it is made available.  Until then please refer to the format in the datasheet.

    One consideration when communicating with this device is that it requires CRC by default.  The CRC equation for this device is X^4+X+1.  The start seed will be 0b1111. 

    The following document does provide some details regarding how CRC algorithms work, but please note the equation is different for the devices referenced.

    https://www.ti.com/lit/ug/slau398f/slau398f.pdf?ts=1599237839798&ref_url=https%253A%252F%252Fwww.google.com%252F

    CRC provides error checking in communication, but there is an option in register 0x0F that allows it to be disabled.  The following sequence would need to be written to select that option:

    MSB to LSB to send over the SPI: x0F000407

    Thanks,

    Scott

  • Hi, Scott.

    Thanks for the help. But why the last digit is 7 and not 5?

    4^4 + 4 + 1 = 261, 261 - 256 = 5

    Or am I calculating the CRC wrong?

    Regards,

    Alexander

  • I found a CRC4-ITU C implementation /https://github.com/mozram/CRC4-ITU/blob/master/crc4_itu.c/, but I'm not sure if it is correct.

    Would love to see this function from TI.

    Regards,

    Alexander

  • CRC is not implemented through subtraction.  Rather, the equation specifies a binary pattern that will be iteratively used to perform a calculation against the rest of the data transfer.  In our case with X^4+X+1 this translates to 0b10011.

    Code for a device with a longer polynomial is available as a reference here:

    https://www.ti.com/lit/an/sbaa456/sbaa456.pdf

    Note that for our TMAG5170 the initial value of the CRC result is 0b1111. 

  • OK.

    1. What is the mode of SPI using TMAG5170?

    0, 1, 2, 3?

    i don't see it in the manual.

    2. I applied the code

    // ==========================================================================
    // CRC Generation Unit - Linear Feedback Shift Register implementation
    // (c) Kay Gorontzi, GHSi.de, distributed under the terms of LGPL
    // ==========================================================================
    char *MakeCRC(char *BitString)
       {
       static char Res[5];                                 // CRC Result
       char CRC[4];
       int  i;
       char DoInvert;
       
       for (i=0; i<4; ++i)  CRC[i] = 0;                    // Init before calculation
       
       for (i=0; i<strlen(BitString); ++i)
          {
          DoInvert = ('1'==BitString[i]) ^ CRC[3];         // XOR required?
    
          CRC[3] = CRC[2];
          CRC[2] = CRC[1];
          CRC[1] = CRC[0] ^ DoInvert;
          CRC[0] = DoInvert;
          }
          
       for (i=0; i<4; ++i)  Res[3-i] = CRC[i] ? '1' : '0'; // Convert binary to ASCII
       Res[4] = 0;                                         // Set string terminator
    
       return(Res);
       }
    
    
    // A simple test driver:
    
    #include <stdio.h>
    
    int main()
       {
       char *Data, *Result;                                       // Declare two strings
    
       Data = "1101000101000111";
       Result = MakeCRC(Data);                                    // Calculate CRC
       
       printf("CRC of [%s] is [%s] with P=[10011]\n", Data, Result);
       
       return(0);
       }
    

    of course with 0b1111

    and I do not see CRC "7" from x0F00040

    3. You made a new microcircuit, analog Melexis MLX90395 /https://www.melexis.com/en/product/MLX90395/Triaxis-3D-micropower-magnetometer/

    But why not give users a C code (no SPI, just C code) to quickly learn about your chip?
    Just reading and writing registers.

    Since 2017, I have been working with a good 32-bit ADS1262 and have not seen any problems (there is a CRC as an option), but here the difficulties are out of the blue.

    Regards,

    Alexander

  • Alexander,

    TMAG5170 is currently in an early release stage.  Materials to support this device are still being developed, but we have made it available early to customers to sample and evaluate prior its final release to market. We are currently working to update the datasheet to provide more details around the CRC implementation.

    The SPI mode for this device can be determined from the timing diagrams provided from the datasheet an attached above.  The clock is low when CS is driven low (non-inverted), incoming data is latched on the rising edge.  This corresponds to SPI mode 0.

    Reviewing your code, it looks like you need to adjust this line

    for (i=0; i<4; ++i) CRC[i] = 0; // Init before calculation

    To this

    for (i=0; i<4; ++i) CRC[i] = 1; // Init before calculation

    Also, you should pad the end of BitString with "0000" to force it to 32 bits before running the calculation.

    If I've followed your code correctly, I think you currently get b01011 as an output from an input of x0F00040, but with these changes to the CRC calculation I believe you should get b00111.

    
    

  • Scott,

    thanks again for your help and patience.

    Yes, with the addition of "0000" to x0F00040 (crcinit of course "1111") we finally got the required number "7" using the function from Dr. Gorontzi.

    Now let's try to carry out a number of operations.

    1. Read "register 4" 2 times (8400000E).

    First reading:           40 7D 83 01

    Not bad, PREV_CRC_STAT = 0, ERROR_STAT = 0, reset = 0x7D83, though CRC from Dr. Gorontzi is "0", not "1"

    Second reading:      60 7D 83 81

    Here is worse, ERROR_STAT = 1 ("ERROR_STAT indicates if there is any error bit flipped in the part").

    Can you explain what this means ("error bit flipped in the part")?

    ---

    2. Read "register 4" (8400000E) and "register 0" (8000000F).

    First reading:           40 7D 83 01 (As in the first case)

    Second reading:      E0 7D 83 81

    Why 0x7D83, not 0x000 (for "register 0" reset = 0x0)?

    ---

    3. Ok, let's try to disable CRC and read  "register 4".

    0F 00 04 07                SPI returns 40 00 00 0A (CRC OK with function from Dr. Gorontzi)

    84 00 00 0E                SPI returns 40 00 00 0A

    ---

    It seems that after the transmission of the first 32 bit command SPI (realy 4x8), some more action is needed.

    I tried these examples in mbed os, but I don't think it is essentialI.

    Regards,

    Alexander

  • Alexander,

    On your second reading we see both the ERROR_STAT bit go high and the ALRT_STATUS1 bit go high.  The ALRT_STATUS bits correspond to D[ 1:0 ] of the CONV_STATUS register.  This bit indicates SYS status error which can be caused by events such as an SPI error.   Also, on the first read we have the CFG_RESET bit high already.  It appears that you have caused a hardware reset by forcing the supply voltage too low. 

    When I attempt the same pattern as you using the EVM I see:

    84 00 00 00 0E producing 00 7d 83 03 

    followed by

    80 00 00 00 0F producing 00 00 00 09 

    I captured both events using a logic analyzer to confirm.  If you haven't tried yet, I would recommend you check your SPI waveforms to ensure everything looks clean and meets the timing requirements for the device.  In every case, the code I manually calculate for CRC matches what is produced by the device. I expect that the incorrect CRC code you observed on the first read correlates with the SYS status error the device is reporting.

    Also, in your case, when you attempted to read register 0, the CRC_Error bit is enabled.  However, your input command is correct.  This also would suggest that maybe the transmission is not being received correctly.

    You might also try to read register 0xD for information about the AFE status and 0xE for more information regarding what is causing the SYS error.

    Thanks,

    Scott

  • Hi, Scott.

    I figured out what the problem was.

    Earlier I worked with ADS1220 and ADS1262, for which it is permissible to connect the CS signal to the ground.

    For TMAG5170 this cannot be done, this chip requires mandatory switching CS from zero to one and vice versa.

    I wrote 32-bit big-bang (without SPI) and now I can read all registers without error.

    The first command is desirable to read register D to clear the flag CFG_RESET.

    Thanks for the help. I learned something about CRC, and for a week my head was constantly busy solving the problem :)