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.