cancel
Showing results for 
Search instead for 
Did you mean: 

About generateBuff and getBuffPtr

Sam Q.
Associate III
Posted on November 15, 2017 at 12:02

Hi everyone,

I'm now trying to start establishing communication between STM32F4 Discovery Board and an SPI slave over SPI1.

There is an example project named 'SPI_Test.slx' in the path \STM32-MAT\STM32\STM32demos\Test\SPI. But I can't well understand, what's the main work of the MATLAB Function block 'generateBuff' that is used in this project.

My thought:

1) Before transmitting data over SPI, this data must be temporarily stored in a buffer. This MATLAB Function block generates a 32-bit buffer to store the data that is going to be sent. Right?

2) The output 'Buff' refers to the address of the generated buffer, in which the data are stored. Right?

3) Another output port 'NbChar' indicates how many numbers of data will be sent. Right?

4) The Buffer_Size_Send value in the SPI block must be equal to Nb2Send. Right?

Thank you very much!

#buffer #spi #stm32-mat
3 REPLIES 3
Sam Q.
Associate III
Posted on November 15, 2017 at 13:54

Here, I want to add more information about thetest model that is extracted from the example model, as shown below.


_legacyfs_online_stmicro_images_0690X0000060MxDQAU.png

To analyze the output results of MATLAB Function block, I generated code for this model, ranit by using Simulink external mode and moniteredsignalesultsviaScope.


_legacyfs_online_stmicro_images_0690X0000060MzhQAE.png

The1st channel shows that there are three data comming into the MATLAB Function block, i.e. 6, 64 and 0.

The 2nd channel indicates that there are totally 3 data that will be sent.

As for the 3rd channel, its output value is equal to 5368856 Does it mean the address of the buffer, in which the data are temporarily stored?By the way, dec2hex(536885648) = 0x200039

Thanks for any idea!

Sam Q.
Associate III
Posted on November 15, 2017 at 14:37

This time, I want to send only one number instead of sending three. So I just removed the other two constant blocks, as shown below.


_legacyfs_online_stmicro_images_0690X0000060MzmQAE.png

However, when Keiliscompiling the generated code, two errorsoccur reporting that:

Error 1:

spi.c(54): error: #167: argument of type ''unsigned int'' is incompatible with parameter of type ''void *''

getBuffPtr(6U);

Error 2:

spi_data.c(35): error: #20: identifier ''P_spi'' is undefined

P_spi spi_P = { 6U };

I wonder if the example modelor the MAT/TARGET library that STM provides is ill designed? Such errorscouldmakemodel based design combining Simulinkwith STM32 MAT/TARGET Librarymuch more difficult.

Sam Q.
Associate III
Posted on November 16, 2017 at 10:11

I tried to use external mode to moniter the activity of the SPI block. So I added an SPI block into theSimulink model, as shown below.But afterdownloading the code tothe board,simulink failed to connect to the target reporting a timeout error.

0690X0000060PE3QAM.png

Does it mean that we can't use the external mode when the model has SPI block? If so, why?