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.

TMS37157 SPI Application note

Other Parts Discussed in Thread: TMS37157, MSP430F2274

Hi,

In the one of the application note "Using the SPI library for TMS37157 "( http://www.ti.com/lit/an/swra272/swra272.pdf ) , it says it is possible to read, write and trim the TMS37157 from the MSP430F2274 microcontroller using SPI.  

In order to trim the LC circuit, the application note says the function

 SPI_TRIM_W_PROG (char data)

 can be used. In this function what is the char data?  How can i find what value for char data that should be passed  to the function?  

I am not able to trim my prototype design using the LF interface.  The external reader I am using is the one that came with the EZ430 TMS37157 (Palfi) kit.  Is there any other pages i need to initialize to get the design communicate with the external reader? 

I am using IAR embedded work bench (kickstart version) for debugging.  In the debugging mode, how can i read the page information? 

I am using the following function  for that

SPI_Read_UserPage (unsigned char ucPage, unsigned char *ucData)

I am not sure where I can see the information in the page in IAR when debugging. 

Any help for this will be greatly appreciated.

Thanks,

Anand

This is the code I am using to read the page

#include "msp430x22x4.h"

#include "PaLFI_Transponder.h"

void main (void)

{
unsigned char ucWDT_Count;
unsigned char ucPageData[5] = {0};
MSP430_SPI_Init();
SPI_Read_UserPage(Page9,ucPageData);
SPI_Power_Down();
}

  • Hi Anand,

    Many questions at once, I will try to answer as much as possible:

    The "data" parameter of the Trim function holds the value for the LF trim array. Simply put, the higher the value, the higher is the added capacitance to the LF interface. MSB is not used, so program 00h for the smallest capacitance (=highest resonance frequency) or 7Fh for the biggest capacitance (=lowest resonant frequency). The challenge is to find out what value fits best. To do this you should measure the frequency after each programming (also done via SPI). Check out this guide I wrote some time ago: SLOA180.

    As a side note: It is not possible to read out the trim data! (For technical reasons)

    To verify your SPI interface, I recommend writing data to the user EEPROM and read it back afterwards.

    To find out what you read back, I recommend setting a break point at the end of your function and add "ucPageData" to watched variables. Again, to make sure you read recognizable data I suggest to write something to the page before.

    Hope that helps for the start.

    Best regards

    Max

  • Hi Max,

    Thanks for the reply.  And sorry for too many questions :)  I was stuck with this for two weeks and was not sure how to fix this problem. 

    I wrote the code for trimming for maximum frequency as follows. 

    #include "msp430x22x4.h"

    #include "PaLFI_Transponder.h"

    void main (void)
    {

    int trimData = 0;
    //Wake_PaLFI();
    MSP430_SPI_Init();
    SPI_TRIM_W_PROG(trimData);

    SPI_Power_Down();
    }

    I didn't have any problem compiling and downloading to the microcontroller.  Just want to check if i am missing anything there as the code seems very short.  

    Also I am not sure how to measure the frequency using SPI after programming the trimming value.  Do I have to use timers?  Or is there any other way? 

    Thanks,

    Anand

  • Hi Anand,

    No problem at all, I'm glad to help!

    I see that you have commented out "Wake_PaLFI()", is there a reason for that? It might be a problem.
    Apart from that, the code looks absolutely fine. Actually it is not more complicated than that to program a specific capacitance to a device. After all you only program a single byte.
    In the sample code you're referencing, there is a routine for automatic trimming to 134.2kHz called "int autotrim(void)" in file "PaLFI Demo.c", which you could use. Yes, timers are involved.

    Godspeed and let me know if this worked out!

    Best regards
    Max

  • Max, 

    I thought initializing the SPI was good enough in the first place. Now I see that I need to add "Wake_PaLFI()" too after initializing SPI.  

    I have one more question. By downloading the code, will the "trimData" be written to the EEPROM of TMS37157 or that will happen during debugging? Or I have to do anything else like a PUSH BUTTON to start the process?  I do not have a PUSH BUTTON in my design.  But I am sure I can do something else to mimic this action if needed.    For programming the page too, do I have to do something else than downloading the code to the microcontroller?  The following is the code I am using to program the page

    #include "msp430x22x4.h"

    #include "PaLFI_Transponder.h"

    void main (void)
    {
    unsigned char ucWDT_Count;
    unsigned char ucPageData[5] = {0,1,2,1,0};
    MSP430_SPI_Init();
    Wake_PaLFI();
    SPI_Program_UserPage(Page10,ucPageData);
    SPI_Power_Down();
    }

     

    I am working on how to use the function "int autotrim(void)"  to measure the frequency.  I understand the timer calculates the time for 800 clock cycle of CLK_AM.  I think, I can use the code under the autotrim function after "Wake_PaLFI()" and can trim the LC tank at once.  I can find the frequency if i watch the variable "time"  in the program.  

    Thanks for all your help.  I appreciate it. 

    Anand

  • Hi Anand,

    The trimData is programmed to the device whenever you execute the code. That is either by debugging (I don't know if single stepping works, though) or by simply flashing the device and do a reset as usual with controllers after flashing. However, if that's what you want to do with the controller I recommend to use some sort of power down state for the microcontroller after the routine above. The behavior at the end of main() function seems not defined for me. I'd suggest to check the corresponding MSP430 User's Guide how to use the low power mode on your device.

    Thanks for your feedback!

    Best regards,
    Max