How do I configure SPI communication with another MCU (DSP, 28377D)?

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

How do I configure SPI communication with another MCU (DSP, 28377D)?

1,407 Views
SeokJin
Contributor II

Hi.

I would like to perform SPI communication between the MCU I have, TMS320F28377D, and KW36.

I want to set TMS320F28377D as Master and FRDM-KW36 board as Slave.

SeokJin_1-1702301842354.png

 

This is how I want to communicate.

 

In this case, do I need to make separate settings on the FRDM-KW36 board? Or can I set it only in the master module, F28377D?

This is a necessary process for implementation, so I hope you can help.

Thank you.

0 Kudos
Reply
9 Replies

1,387 Views
EduardoZamora
NXP TechSupport
NXP TechSupport

Hello @SeokJin

Please, take a look at the MCUXpresso SDK API Reference Manual_MKW36Z4 inside KW36 SDK docs folder > docs. This Reference Manual should provide a set of APIs for peripheral initialization/configuration/operation for optimization/customization purpose; Chapter 11 DSPI: Serial Peripheral Interface Driver provides more information on the DSPI Driver.

Also, you can refer to the basic driver examples codes from the SDK to start with the typical use cases of the different peripherals and drivers such as DSPI module. DSPI example codes should be located inside SDK projects > driver_examples > dspi. These examples may require two boards, one used as DSPI master, and another used as DSPI slave. Please, consider using these projects as a reference for peripheral configuration and usage.

Regards,
Eduardo.

0 Kudos
Reply

1,374 Views
SeokJin
Contributor II

Thank you for answer. I will refer to it and study further.

In relation to this, I think all examples in the SDK are based on functions (Library).
Are there any Bitfield examples? Since it is all composed of libraries, it is not easy to understand.
However, I have searched for Bitfield examples in the SDK so far and cannot find them.
Is there nothing there?

I'm waiting for your reply. thank you

Regard,
SeokJin

0 Kudos
Reply

1,358 Views
EduardoZamora
NXP TechSupport
NXP TechSupport

Hi,

The purpose of the MCUXPresso SDK is to speed up and simplify development of embedded applications by providing stateless, high-performance, ease-of-use APIs that can be used across multiple devices within the product family without modification.

If you wish, you could access the definition of the drivers included in the drivers folder of your project for a lower-level reference; the user is able to modify the peripheral drivers if necessary.

Regards,
Eduardo.

0 Kudos
Reply

1,313 Views
SeokJin
Contributor II

Dear Eduardo,

Hi.

We are currently implementing 8-bit or 16-bit SPI communication with another MCU (DSP, 28377D) as the master and FRDM-KW36 as the slave.

I am replying because a problem occurred while studying and implementing based on the previous answers.

I would like to ask you a few questions.

 

1. First of all, we are currently using the 'frdmkw36_driver_examples_dspi_interrupt_b2b_transfer_slave' example of the KW36 SDK to operate the FRDM-KW36 as a slave. There was no part to set the slave's baud rate in the example. Is it not there originally? I am curious as to whether the baud rate set by the master is automatically recognized when operating as a slave.

I've been looking for it so far, but I couldn't find it. If there is a part that sets the slave's baud rate, please let me know.

 

2. The second problem occurs during SPI communication.

First, this is the case when SPI communication is performed in 8bit.

Let me show you the master setup.

SeokJin_5-1702570359876.png Master SPI initialization

SeokJin_7-1702570492855.png transfer function

SeokJin_8-1702570509131.png Transfer and update variable k

As you can see in the picture, this is an example of 8-bit communication set up in the DSP and transmission while updating the variable k. baud rate is 500kHz.

 

For slave settings during 8bit SPI communication, the base code from the example was used.

The hardware was checked and found to be complete.

Now we will show you the communication results.

SeokJin_10-1702570786156.pngWhen updated to k = k+1

SeokJin_12-1702570917306.png When updated to k = k+2

SeokJin_13-1702570943874.png When updated to k = k+4

SeokJin_26-1702571832425.png When updated to k = k+6

 

As you can see from the results, communication becomes a mess depending on how the k value is updated. When updating k = k+4, you can see the data being received increasing by 2, but the value received cannot exceed '128'.

I think the master code is somewhat complete, so I wonder if there might be a problem with the slave code. Is there something I missed?

3. This problem occurs when doing 16bit SPI communication.

A similar problem occurs during 8bit communication.

SeokJin_17-1702571366005.pngMaster SPI initialization

SeokJin_18-1702571391703.png transfer function

SeokJin_8-1702570509131.png Transfer and update variable k

The only thing that changed from the master was the code modification for 16bit. baud rate is still 500kHz.

When using 16-bit communication, the slave code was slightly modified.

SeokJin_19-1702571547743.png 16bit data type change

SeokJin_20-1702571572132.png 16bit mode setting

SeokJin_21-1702571587280.png Change slaveXfer.rxData data type

The slave code has been modified to this extent, but is additional modification required?

 

This is the result of communication.

SeokJin_23-1702571765024.png When updated to k = k+1

SeokJin_24-1702571790875.png When updated to k = k+2

SeokJin_25-1702571810450.png When updated to k = k+4

SeokJin_29-1702572325289.png When updated to k = k+6

 

Similar problems as 8-bit communication occur during 16-bit SPI communication. I also think that the updating value is divided by 2 to update it. (For example, if k = k+4, it increases by 2, and if k+20, it increases by 10.) Also, out of the 16 data, only the first 8 are read and the last 8 are output as 0.

 

This is the point where I felt a problem while performing the task, and I couldn't solve it, so I'm asking a question. Is there anything I need to improve or am I missing?

Thank you for reading this long article. The article is long because I have to explain it in detail.

If you have any additional questions, please let me know. I'm waiting for your reply.

 

Thank you

Best Regard,

SeokJin.

0 Kudos
Reply

1,305 Views
EduardoZamora
NXP TechSupport
NXP TechSupport

Hi,

In Slave mode, the SCK signal is configured as input and driven by an SPI bus master.

If you run the SPI driver demo using two FRDM-KW36, this is the output you should get:

EduardoZamora_0-1702593937495.png

Please, confirm that the relevant clock and transfer attributes match for both your master and slave devices. The following is the default slave configuration (perhaps Clock Polarity and Phase do not match):

EduardoZamora_1-1702593937496.png

Regards,
Eduardo.

 

0 Kudos
Reply

1,299 Views
SeokJin
Contributor II

Dear Eduardo,

 

Hi.

Currently I have compromised by simply sending a random integer.

SeokJin_0-1702608219923.png These integers are the data I will send.

Therefore, 16-bit communication is planned, and the [DSP, F28377D (Master)] settings are set to 16-bit mode as previously attached.

SeokJin_1-1702608404514.png

SeokJin_2-1702608453075.png

16bit communication, baud rate is 500kHz, data is transmitted with 16bit transmission function.

SeokJin_3-1702608534691.png In theory, the numbers 11120, 888, 3256, and 5680 would be transmitted repeatedly.

 

FRDM-KW36(Slave) is also set to enable 16bit communication.

SeokJin_4-1702608691202.pngSeokJin_5-1702608706220.png

 

Now, 16bit SPI communication between Master and Slave begins.

SeokJin_8-1702609066671.png I think communication is going well. But the data I sent is divided by 2? In this case, did I configure it wrong? Or is the data originally divided by 2 coming in? I think it's the former, but...
This is the first question I would like to ask.

SeokJin_9-1702609315400.png

SeokJin_6-1702608801176.png I have to correct the output value through *2 in the slave receive buffer for the data I sent to appear... But anyway, it seems that half of the transmitted data will be stored in the slave receive buffer. Did I set this incorrectly?

The next question is one I've asked before, but is the answer simply because I didn't implement the slave settings properly?

SeokJin_10-1702609562198.png Why are the last 8 digits of the slave receive buffer displayed as '0'?

 

It seems like almost everything has been implemented, but I'm asking because I feel like minor problems may become obstacles in the future.

I'll be waiting for your reply. thank you

 

Regard,

SeokJin.

0 Kudos
Reply

1,261 Views
EduardoZamora
NXP TechSupport
NXP TechSupport

Hi,

Based on your last reply, according to the SPI Clock config of your master device:

EduardoZamora_0-1702682210362.png

It may not match the configuration of your slave device:

EduardoZamora_1-1702682210365.png

Could you please try setting these parameters to a common value and test the communication again? After this, please let me know your findings.

Also, it would be very helpful if you could provide a capture of the data exchange using a logic analyzer/oscilloscope.

Regards,
Eduardo.

0 Kudos
Reply

1,193 Views
SeokJin
Contributor II

Hi.

We conducted several experiments related to CPOL and CPHA. The CPOL and CPHA I currently use are (0, 0), (0, 1), and (1, 0), respectively.

I set the slave's CPOL and CPHA according to the master's CPOL and CPHA and tested to see if communication was possible.

As a result of the experiment, when the Master's CPOL and CPHA are (0, 1) respectively, smooth communication proceeds when the Slave's CPOL and CPHA are set to (1, 1). Additionally, communication is also possible when the Master's CPOL and CPHA are (1, 0) and the Slave's CPOL and CPHA are (1, 1).

In all other cases, SPI communication is not connected at all, or even if communication is established, the transmitted value is not properly received and a completely irrelevant received value is output.

SeokJin_0-1702951080765.png When set to Master CPOL, CPHA(0, 1), Slave CPOL, CPHA(1, 1), the result is normal communication.

 

If settings other than Master CPOL, CPHA(0, 1), Slave CPOL, CPHA(1, 1) or Master CPOL, CPHA(1, 0), Slave CPOL, CPHA(1, 1) are set, SPI communication does not work normally. Does not.

SeokJin_1-1702951218535.png This is the communication result when set to Master CPOL, CPHA(0, 1), Slave CPOL, CPHA(0, 1).

 

Even if communication is normal, 16 pieces of data should be received, but only 8 pieces of data are received and 0 is output for the 8 pieces of data. This phenomenon has not been fixed, but we will try to proceed like this.

SeokJin_2-1702951576513.png

As a result of what I have done so far, the above problem does not seem to be related to the agreement between CPOL and CPHA. Are there any other technical issues??

 

Regard,

SeokJin.

0 Kudos
Reply

1,152 Views
EduardoZamora
NXP TechSupport
NXP TechSupport

Hi,

dspi_transfer_t::dataSize should be used by the DSPI driver to set the Byte Count. Maybe you can try doubling your current dataSize value.

EduardoZamora_0-1703107670086.png

Regards,
Eduardo.

0 Kudos
Reply