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.
Hello.
I am using SPI communication with F28335 and MAX31856 (temperature measuring module).
The problem is that the MOSI line must be reset to receive the received value.
Could the above phenomenon be caused by a problem in the code?
As an additional question, each line is currently connected using a 30cm jumper cable.
Is the accuracy of the temperature value affected by the length of the jumper cable?
There is a lot of error in the temperature value, and sometimes the temperature value bounces.
(Example: Current temperature 20 / Measured temperature 5
Current temperature 70 / Measured temperature 100 )
#include "DSP28x_Project.h"// Device Headerfile and Examples Include File
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Global variables used in this system
Uint16 TxBuff[4];
Uint16 TxFifoLevel;
Uint16 RxFifoLevel;
Uint32 i;
Uint16 RxBuff[4];
Uint16 temp;
float32 tempC;
Uint32 LoopCount;
void main(void)
{
//============================================================================================
// Step 1. Disable Global Interrupt
//--------------------------------------------------------------------------------------------
DINT;
//============================================================================================
//============================================================================================
// Step 2. 시스템 컨트롤 초기화:
//--------------------------------------------------------------------------------------------
// 초기화 시작
// PLL, WatchDog, enable Peripheral 클럭의 초기화
// DSP280x_SysCtrl.c 에 정의된 함수.
// 2.1 Disables the watchdog
// 2.2 Set the PLLCR for proper SYSCLKOUT frequency
// 2.3 Set the pre-scaler for the high and low frequency peripheral clocks
// 2.4 Enable the clocks to the peripherals
//--------------------------------------------------------------------------------------------
InitSysCtrl();
//============================================================================================
//============================================================================================
// Step 3. SPI setting
//--------------------------------------------------------------------------------------------
InitSpiaGpio();
// SPI 주요설정
SpiaRegs.SPICCR.bit.SPISWRESET=0; // SPI 소프트웨어 리셋
SpiaRegs.SPICCR.bit.SPICHAR =7; // SPI 송수신 Charcter-length 설정 : 16bit
SpiaRegs.SPICCR.bit.SPILBK = 0; // SPI 루프백 테스트 모드 Enable
SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1; // SPI Master/Slave 설정 : Master 모드
SpiaRegs.SPICTL.bit.TALK = 1; // SPI Master/Slave 통신 Enable
SpiaRegs.SPIBRR = 24; // SPI 통신속도 설정: 37.5MHz/(SPIBRR+1) = 1.5MHz
SpiaRegs.SPICCR.bit.CLKPOLARITY =1;
// SPI의 송신 FIFO 설정
SpiaRegs.SPIFFTX.bit.SPIFFENA = 1; // SPI FIFO 사용 설정 Enable
SpiaRegs.SPIFFTX.bit.TXFIFO = 1; // SPI 송신 FIFO RE-enable
// SPI의 수신 FIFO 설정
SpiaRegs.SPIFFRX.bit.RXFIFORESET = 1; // SPI 수신 FIFO RE-enable
SpiaRegs.SPICCR.bit.SPISWRESET=1; // SPI 소프트웨어 리셋 해제
//============================================================================================
//============================================================================================
// Step 4. Initialize Application Variables
//--------------------------------------------------------------------------------------------
for(i=0;i<4;i++){
TxBuff[i] = 0;
}
/*
for(i=0;i<4;i++){
RxBuff[i] = 0;
}
*/
TxFifoLevel = 4;
RxFifoLevel = 4;
LoopCount = 0;
//============================================================================================
//============================================================================================
// Enable global Interrupts and higher priority real-time debug events:
//--------------------------------------------------------------------------------------------
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
//============================================================================================
//============================================================================================
// IDLE loop. Just sit and loop forever :
//--------------------------------------------------------------------------------------------
while(1)
{
/*---------------------------------------------------------------------------
A. SPI 데이터 송신
---------------------------------------------------------------------------*/
while(SpiaRegs.SPIFFTX.bit.TXFFST != 0);
for(i=0;i<TxFifoLevel;i++)
{
TxBuff[0]=0x0c; // 주소바이트
TxBuff[1]=0x00; // 더미바이트
TxBuff[2]=0x00; // 더미바이트
TxBuff[3]=0x00; // 더미바이트
SpiaRegs.SPITXBUF = (TxBuff[i]<<8);
}
/*---------------------------------------------------------------------------
B. SPI 데이터 수신
---------------------------------------------------------------------------*/
while(SpiaRegs.SPIFFRX.bit.RXFFST < RxFifoLevel);
for(i=0;i<RxFifoLevel;i++)
{
RxBuff[i] = SpiaRegs.SPIRXBUF;
}
tempC = 0.0625*(256*RxBuff[1]+RxBuff[2]); // 온도 변환 코드
if(tempC>=4000)tempC=0; // RxBuff의 비트의 합이 4000이 넘어갈 경우 0으로 표시, 오류 확인
/*---------------------------------------------------------------------------
C. 일정 주기로 데이터를 전송하기 위한 딜레이
---------------------------------------------------------------------------*/
DELAY_US(10000);
/*---------------------------------------------------------------------------
D. 다음에 송신할 데이터를 변경
---------------------------------------------------------------------------*/
for(i=0;i<TxFifoLevel;i++){
TxBuff[i]++;
}
LoopCount++;
}
//============================================================================================
}
//============================================================================================
// 메인 함수 - 끝
//============================================================================================
This is the code I wrote.
thank you.
Hello Gangin,
The long wire could be having an effect. I would try to see if there is any effect by changing to a smaller wire, if possible. I would recommend you also check at a lower SPICLK frequency (not sure what frequency you are using now). Lastly, check the phase and clock polarity settings on the SPI configuration and make sure these match the settings required by the temp sense device (please note review the timings in the SPI user guide carefully).
Hello
I checked by changing to a smaller wire and the same symptom occurs.
Can I activate CLK by setting the STE pin to LOW and then giving DELAY?
Can I activate CLK by setting the STE pin to LOW and then giving DELAY?
You can always configure the STE pin as a regular GPIO pin. In your code you could set the GPIO low, add SW delay, then start the SPI transfer. Is this what you want to do?
The problem is that the MOSI line must be reset to receive the received value.
Going back to your original problem description. Can you explain what this means?
I'm looking at the timing on the MAX31856, but I'm having a hard time understanding it.
I have to reconnect the MOSI pin to get the temperature value.
Sometimes it is possible to read the exact temperature value.
Is it because the timing is right by chance?
thank you.
I'm looking at the timing on the MAX31856, but I'm having a hard time understanding it.
You'll have to contact Maxim/ADI for specific questions on that device.
I have to reconnect the MOSI pin to get the temperature value.
Sometimes it is possible to read the exact temperature value.
Is it because the timing is right by chance?
Yeah, this is not normal. The SPI connection is very straight forward. The first step is to ensure the SPI electrical timings (clock timings, data hold, data setup) are being met. Per the MAX31856 data sheet, either clock polarity can be supported, so you just need to ensure the data is driven on the correct edge of the clock. For CPOL=1, the MAX31856 shows that the SDI (aka MOSI) pin is sampled on the rising edge of SCLK. From the MCU standpoint you would want CLKPOLARITY = 1, CLK_PHASE = 0 (see Figure 9-5 in F28335 TRM). It looks like this is what you have in your code. What SCLK frequency are you using? Have you probed the CS, SCLK, MOSI, MISO pins during a write or read transaction to verify timings?
The second step would be to ensure you are sending the right commands on the MAX31856 device. Have you verified the correct commands and sequence is generated on the SPI bus?
SCLK is in use below 5MHz.
When you check with the oscilloscope, it is judged that you are transmitting correctly.
I think it sends a command of 0x0c to read the temperature value.
5MHz is at the limit of the MAX31856. Since you are using long wires to connect the devices, I would recommend to reduce the frequency to something really slow, e.g. 100kHz, and try again. Please post any oscilloscope plots you may have of the actual SPI transaction.