mimxrt685 evk SPI transfer data to max7219 LED matrix module

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mimxrt685 evk SPI transfer data to max7219 LED matrix module

1,100 Views
Durant19
Contributor I

Hello i am using the mimxRT685 evk and use spi function to communicate with max7219 and lora lr1110

and i search for the example on sdk spi_polling_b2b_transfer_master

and modify the tx buffer to command the max7219 and lora module, but seems that its not working

below is my code:

i use SPI_MasterTransferBlocking function and the transfer is success, but its just not working

and for lr1110, the rx data buffer are all 0, do not have the response data.

thanks.

#include "fsl_spi.h"
#include "board.h"
#include "fsl_debug_console.h"

#include "pin_mux.h"
#include "clock_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define EXAMPLE_SPI_MASTER SPI5
#define EXAMPLE_SPI_MASTER_IRQ FLEXCOMM5_IRQn
#define EXAMPLE_SPI_MASTER_CLK_SRC kCLOCK_Flexcomm5
#define EXAMPLE_SPI_MASTER_CLK_FREQ CLOCK_GetFlexCommClkFreq(5U)

#define EXAMPLE_SPI_SSEL 0
#define EXAMPLE_SPI_SPOL kSPI_SpolActiveAllLow

/*******************************************************************************
* Prototypes
******************************************************************************/

/*******************************************************************************
* Variables
******************************************************************************/
#define BUFFER_SIZE (64)
static uint8_t srcBuff[8];
static uint8_t destBuff[8];
/*******************************************************************************
* Code
******************************************************************************/

int main(void)
{
spi_master_config_t userConfig = {0};
uint32_t srcFreq = 0;
uint32_t i = 0;
uint32_t err = 0;
spi_transfer_t xfer = {0};

CLOCK_AttachClk(kSFRO_to_FLEXCOMM5);

BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
PRINTF("\n\rMaster Start...\n\r");
/*
userConfig.enableLoopback = false;
userConfig.enableMaster = true;
userConfig.polarity = kSPI_ClockPolarityActiveHigh;
userConfig.phase = kSPI_ClockPhaseFirstEdge;
userConfig.direction = kSPI_MsbFirst;
userConfig.baudRate_Bps = 500000U;
*/
SPI_MasterGetDefaultConfig(&userConfig);
srcFreq = EXAMPLE_SPI_MASTER_CLK_FREQ;
userConfig.sselNum = (spi_ssel_t)EXAMPLE_SPI_SSEL;
userConfig.sselPol = (spi_spol_t)EXAMPLE_SPI_SPOL;
SPI_MasterInit(EXAMPLE_SPI_MASTER, &userConfig, srcFreq);

srcBuff[0] = 0x11;
srcBuff[1] = 0x10;
srcBuff[2] = 0x10;
srcBuff[3] = 0x11;
srcBuff[4] = 0x11;
srcBuff[5] = 0x11;
srcBuff[6] = 0x11;
srcBuff[7] = 0x11;

/*Start Transfer*/
xfer.txData = srcBuff;
xfer.rxData = destBuff;
xfer.dataSize = 8;
xfer.configFlags = kSPI_FrameDelay;
if(SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer) == kStatus_Success){
PRINTF("Transfer success!\n");
}
else{
PRINTF("Transfer failed QQ~\n");
}


PRINTF("%x %x\n\r", srcBuff[0], srcBuff[1]);
PRINTF("%x %x\n\r", destBuff[0], destBuff[1]);

while (1)
{
}
}

Labels (1)
0 Kudos
5 Replies

1,070 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Durant19,

  Do you have oscilloscope ? Check the SPI bus, whether it has the data or not?

   Please also double check your pins, make sure you connect the correct pins.

Master_board(SPI5)
Pin Name Board Location
MISO J28 pin 5
MOSI J28 pin 4
SCK J28 pin 6
PCS0 J28 pin 3
GND J28 pin 7

More details, read the SDK project readme.

The SDK SPI code has been tested, it works OK.

That's why I suggest you check the SPI bus in the oscilloscope.

 

Best Regards,

Kerry

0 Kudos

1,074 Views
Durant19
Contributor I

update another problem, cause i do not have the device you mentioned.

due to the fail communication with lr1110,  i decided to use the arduino as slave to debug

 i use the sdk spi polling master example to transfer data

and it just still not working.... so i think is the sdk borad's problem not lr1110

i think the spi examples are very hard to read, and the example just tell how to transfer between two nxp, its not a good example....

my arduino spi slave code:

/* SPI Slave Demo
*
* SPI pin numbers:
* SCK 13 // Serial Clock.
* MISO 12 // Master In Slave Out.
* MOSI 11 // Master Out Slave In.
* SS 10 // Slave Select . Arduino SPI pins respond only if SS pulled low by the master
*

*/
#include <SPI.h>
#include<stdint.h>
#define SPI_SCK 13
#define SPI_MISO 12
#define SPI_MOSI 11
#define SPI_SS 10

uint8_t dataBuff[500];

//Initialize SPI slave.
void SPI_SlaveInit(void)
{
// Initialize SPI pins.
pinMode(SCK, INPUT);
pinMode(MOSI, INPUT);
pinMode(MISO, OUTPUT);
pinMode(SS, INPUT);
//make SPI as slave

// Enable SPI as slave.
SPCR = (1 << SPE);
}

//This function returns SPDR Contents
uint8_t SPI_SlaveReceive(void)
{
/* Wait for reception complete */
while(!(SPSR & (1<<SPIF)));
/* Return Data Register */
return SPDR;
}


//sends one byte of data
void SPI_SlaveTransmit(char data)
{
/* Start transmission */
SPDR = data;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));
}

// The setup() function runs right after reset.
void setup()
{
// Initialize serial communication
Serial.begin(9600);
// Initialize SPI Slave.
SPI_SlaveInit();
Serial.println("Slave Initialized");
}

// The loop function runs continuously after setup().
void loop()
{
uint32_t i;
uint8_t dataLen = 0;
Serial.println("Slave waiting for ss to go low");

while(digitalRead(SS)){
Serial.println("Waiting SS");
delay(5000);
};
Serial.println("Reciving data...");
i = 0;
dataLen = SPI_SlaveReceive();
for(i = 0 ; i < dataLen ; i++ )
{
dataBuff[i] = SPI_SlaveReceive();
}

// Serial.println(String(i,HEX));
dataBuff[i] = '\0';

Serial.println("Rcvd:");
Serial.println(dataBuff[0]);
Serial.println(dataBuff[1]);
Serial.println(dataBuff[2]);
Serial.println(dataBuff[3]);
Serial.print("Length:");
Serial.println(dataLen);
}

0 Kudos

1,082 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Durant19,

    Do you have the logic analyzer tool on your side? You can check the SPI bus data, whether that is meet your slave module requirement, you mentioned your  lr1110, the rx data buffer are all 0, so you need to check the RT SPI_MOSI, whether the sendout data is really 0, or just the SPI slave didn't receive the data.

    If you don't have the logic analyzer tool, you also can use the oscilloscope to check the SPI bus data.

    You can check your SPI bus, and give me your SPI wave.

    If the SPI bus already has the data, then you need to check the SPI baudrate, and the SPI mode, whether that is meet your slave demand.

Wish it helps you!

Any updated information, just let me know.

Best Regards,

Kerry

0 Kudos

1,042 Views
Durant19
Contributor I

Hello after the study and use logic analyzer, i found that the problem that lr1110 can not

read the spi transfer might be the logic level voltage, since i use arduino spi can communicate with

LR1110, and the arduino logic voltage is 5v, and on RT685 NXP call it arduino expansion, but the voltage seems to be different compare with arduino.

so is it the only way to use logic level converter to solve this problem? thanks very much

by the way whats the logic level on RT685?, i can not find in the manual.

0 Kudos

1,034 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Durant19

   Thanks for your updated information.

   So it is the voltage unmatch issues between the RT board and your external SPI modules LR1110.

   So, maybe you need to add the external voltage convert circuit if you still want to use the LR1110. 

    You also can check your LR1110, whether that module can support the SPI voltage like the RT685.

 

Wish it helps you!

Best Regards,

Kerry

0 Kudos