Hi all,
I'm trying to use the SPI chip in the evaluation board to communicate with an AdaFruit MAX31865 (with pt1000 sensor). I tried bot SPI 0 and SPI 1 with negative results. I also tried some example code with no success
I attach the SPI Read/Write functions; can anybody point me any evident mistake ?
Does anyone have the possibility to try those functions with other (similar) SPI sensors ?
Thanks a lot!
Alberto
Alberto,
The common error with SPI is overlooking CPOL/CPHA requirements. You have this:
SPI1CR1_CPHA = 0; //Sampling of data occurs at even edges (2,4,6,...) of the SCK clock.
And this is what you may see under MAX31865 datasheet Table 8. Function Table:
Edward
Hi Edward,
thanks very much for your answer.
Actually that is a comment found in nxp demo software and It is in contrast with the reference manual (unless they reverse the clock polarity CPOL).
From S12 referece manual:
CPHA
SPI Clock Phase Bit — This bit is used to select the SPI clock format. In master mode, a change of this bit will abort a transmission in progress and force the SPI system into idle state.
0 Sampling of data occurs at odd edges (1,3,5,...) of the SCK clock.
1 Sampling of data occurs at even edges (2,4,6,...) of the SCK clock.
Based on this I suppose 0 is the correct value (Anyway I tried with 1 with no success).
Regards,
Alberto
No, based on S12Z RM and MAX31865 datasheet correct CPHA=1, sample at even edges (and shift out at odd edges).
Anyway wrong CPHA/CPOL is dead end leading to problems.
SPI1CR1_SSOE = 1; //Use slave select
SPI1CR2_XFRW = 0; // 0 => 8 bit transfers according to Max31865 datasheet
There two don't seem being MAX318xx compatible. Don't have to look deeper into not interesting MAX31865, but it looks like all transfers are 16bits wide. So you could use that in combination with SSOE. Or you could toggle SSOE by hand and use 8 bit trnasfers, /CS should be pulsed once per 16bit transfer, not every 8bit transfer, see timing diagrams in MAX31856 datasheet.
Hi Edward,
I'm sorry, you're definitely right; The correct value for CPHA is 1.
Moreover transfer width is also a problem; thanks for pointing me out that.
I tried to overcome it by setting 16 bit transfers (SPI1CR2_XFRW = 1) but it didn't work.
Now I'm trying to drive the CS by code.
Is there any particular configuration I have to use for the GPIO used as CS ? (pull-up/pull-down/open-drain ?).
Thanks so much for all your usefull help.
Regards,
Alberto
Looking at your code again it seems it is first time you meet SPI interface and you don't understand SPI specifics. To send something you need to pulse CLK N times. To receive something you again need to pulse CLK N times. Receive can't happen without send. Your code seems expecting that read from SPI data register will transfer something from slave. No, you need to initiate transfer by writing to SPI data register, then, after transfer is complete read SPI data register.
In SPI_Write routine first comment for while(SPI1SR_SPTEF==0) {} is OK. But another two are wrong. You aren't waiting there for transfer complete. Transfer complete is signaled with SPIF flag!
In SPI_Read. You need to read SPISR before writing SPIDR(L). Please fix. In while loop you should initiate transfer writing dummy value to SPIDR, then wait for SPIF, and only then read SPIDR(L) back.
Since SPI is double buffered you should wait for SPIF after every transfer, even for those two (or more) bytes in SPI_Write(), else you may loose a track of what is transferred when.
Edward
Resending my message since it seems it got lost.
Hi Edward,
Yes, it is my very first time I interface a SPI chip at this low level.
Anyway, thanks to your usefull suggestions I now have values read from SPI chip!
I still have some doubt on the Max31865 because sometimes it starts to return all zero values until power cycle; osilloscope shows the SDO line as it is shortcutted to ground; Any idea ?
Thanks very much for all your usefull help!
Hi Alberto,
It's hard to guess what's going on without hardware. Do you have any oscillograms? Please attach your latest init, write and read routines.
Hi Edward,
thanks a lot for your usefull support.
We are still having problems reading temperature using the PT1000 (Max31865).
Furthermore We have two different (strange) behaviourson on SPI signals if USB cable connected or not.
Attacched you'll find:
1) noUsb_*.png files; oscillograms with USB cable connected (two different timescale)
2) Usb_*.png files: oscillograms without USB cablle (two different timescale).
Green curve is CS;
Yellow curve is CLK;
Blue curve is SDO line
Do you have any clue why the SDO curve is so bad ?
Also, why is the USB cable shifting the signals ?
Thanks a lot,
regards,
Alberto
Da: "kef2" <admin@community.nxp.com>
A: "Alberto Catoni" <catonia@email.it>
Inviato: Lunedì, 15 aprile 2019 8:52:29
Oggetto: Re: - Re: SPI problem on S12ZVC
NXP Community
Re: SPI problem on S12ZVC
reply from Edward Karpicz in S12 / MagniV Microcontrollers - View the full discussion
Hi Alberto,
It's hard to guess what's going on without hardware. Do you have any oscillograms? Please attach your latest init, write and read routines.
Reply to this message by replying to this email, or go to the message on NXP Community
Start a new discussion in S12 / MagniV Microcontrollers by email or at NXP Community
Following Re: SPI problem on S12ZVC in these streams: Inbox
This email was sent by NXP Community because you are a registered user.
You may unsubscribe instantly from NXP Community, or adjust email frequency in your email preferences
Hi
Well, I don't see anything obviously wrong in your read, write and init routines. As well /CS and SCK on some oscillograms seem confirming proper 16bits transfer while /CS is low. Yes, now you should fix hardware issues.
I've no idea what USB do you have, looks like that when it is attached, something is driving /CS up while MCU drives it down. You need to check your circuit.
Looking at your oscillograms, it seems S12ZVC VDDX is 5V, while MAX31865 is 3.3V device. Do you power MAX31865 from proper 3.3V source? If not, isn't it smoked already? You need to solve somehow SPI signals level shifting between S12Z and MAX or try supplying S12Z VDDX not from internal S12Z voltage regulator but from external 3.3V source.
Edward
I don't see how and where you switch convPhase. case 1 initiates conversion. You need to wait for ~70ms before entering case 2. What time units are in delayT(), milliseconds?
Hi Edward,
Line 187: cycles convPhase in the range increasing by 1 at each function call.
Max31856_ReadRTD is called at 10Hz so there is a 100 ms delay between each phase (I also tryied increasing the delay(up to 500 ms with same result).
delayT(100) is in the order of micro seconds.
Da: "kef2" <admin@community.nxp.com>
A: "Alberto Catoni" <catonia@email.it>
Inviato: Martedì, 7 maggio 2019 10:21:45
Oggetto: Re: - Re: SPI problem on S12ZVC
NXP Community
Re: SPI problem on S12ZVC
reply from Edward Karpicz in S12 / MagniV Microcontrollers - View the full discussion
I don't see how and where you switch convPhase. case 1 initiates conversion. You need to wait for ~70ms before entering case 2. What time units are in delayT(), milliseconds?
Reply to this message by replying to this email, or go to the message on NXP Community
Start a new discussion in S12 / MagniV Microcontrollers by email or at NXP Community
Following Re: SPI problem on S12ZVC in these streams: Inbox
This email was sent by NXP Community because you are a registered user.
You may unsubscribe instantly from NXP Community, or adjust email frequency in your email preferences
No ideas, sorry.
no problem.
Thanks very much for your help.
Da: "kef2" <admin@community.nxp.com>
A: "Alberto Catoni" <catonia@email.it>
Inviato: Mercoledì, 8 maggio 2019 8:59:36
Oggetto: Re: - Re: SPI problem on S12ZVC
NXP Community
Re: SPI problem on S12ZVC
reply from Edward Karpicz in S12 / MagniV Microcontrollers - View the full discussion
No ideas, sorry.
Reply to this message by replying to this email, or go to the message on NXP Community
Start a new discussion in S12 / MagniV Microcontrollers by email or at NXP Community
Following Re: SPI problem on S12ZVC in these streams: Inbox
This email was sent by NXP Community because you are a registered user.
You may unsubscribe instantly from NXP Community, or adjust email frequency in your email preferences
Hi,
The question you are asking is more-less application problem than MCU oriented issue.
Of course, any guy who has real experience with the device you want to communicate with will be the best contact for you if there is any specific feature which could influence a communication.
The problem could be if you have issue with MCU behavior or you are sure that you set everything correctly and you see something different on the bus (confirmed by picture from scope). If I connected it to your issue I would do following:
- Prepare a data what I expect to be sent to the device via SPI and what should be a response.
- If there is no communication I would check whether data line contains expected data with correct polarity and bit rate. (Oscilloscope !!!!)
- If answer is no, SPI setup is wrong.
- If answer is yes I would check whether I sent really correct data with correct timing to the external device to get response from it.
I do not know it will help you but I attached an example from an example pack.
Best regards,
Ladislav
Hi Ladislav,
first of all thanks so much for your kind answer.
Actually I did exacly what you suggested, in particular:
My intention, posting code here, was to check if the SPI Read/Write functions are correct since they should work also with other SPI slaves.
Thanks a lot,
Regards,
Alberto
Hi Alberto,
I am taking vacation and be at work on Monday. I have to put the SPI to the scope to see what it does.
Please confirm me that you have 25MHz busclock - plus please measure it at ECLK pin.
best regards,
Ladislav
Hi Ladislav,
Thanks again for your (vacation) time.
Today I got an Arduino Uno board, connected the Max31865 and It doesn't t work. Looks like the problems is (also) in the sensor itself.
ECLK (pin 47, PT7) shows 6,25 Mhz.
Thanks,
Regards,
Alberto
Hi,
6.27MHz? Really?
Your setup is: SPI1BR =0x07; /* baudrate 97.66 kbit/s*/
If I calculate SPI baudrate = (SPPR+1) * 2^(SPR+1) = 1 * 2^8 = 256
Yuu claim baudrate 97.66 kbit/s => BUSCLK = 97.66*256 = 25MHz
Fiinaly, you wrote the busclk is 6.27MHz which directs me your BUSCLK is not correct.
I would like to suggests you to start with BUSCLK, to be sure I have correct input clock. Then, small game with SPI setup and osciloscope to see what is on the bus and finally communication protocol with external device.
Best regards,
Ladislav
Hi Ladislav,
and again thanks for your help.
Yes It is 6.25Mhz.
The error is in the comment " /* baudrate 97.66 kbit/s*/ !". Sorry for confusing you.
Anyway I tried different values in SPI1BR with same result: nothing happen on the MISO pin. Also, the MAX31865 should be compatible with (almost) any SPI speed.
I’m searching for another SPI sensor (whatever it is) to test my Read/Write functions or maybe I’ll directly buy another Max31865 if I can’t find one.
Thanks.
Regards,
Alberto