Some questions, spi tranfer master and Purpose of SIM->SOPT5 in pin_mux.c?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Some questions, spi tranfer master and Purpose of SIM->SOPT5 in pin_mux.c?

ソリューションへジャンプ
2,255件の閲覧回数
itr1718
Contributor III

Hi guys,

I am beginner at Embedded system and also at Kinetis Design Studio. I am using DIY Board with MKL27Z256 microcontroller. 

1) I test spi transfer with 'polling spi b2b transfer master' example. 

I printed out the result of sent and received data on semihosting console window.

 

My sending data was srcBuff[i] = i; from 0 to buffer size with for function and my received data was initialised as 0. But I got error with the received value 255, not following sent data.

for example, 

srcBuff[4] = 4
desBuff[4] = 255

The 4 data is wrong, the data received is 255

 

I used SPI_MasterTransferBlocking like below.

SPI_MasterGetDefaultConfig(&Mconfig);
srcFreq = CLOCK_GetFreq(kCLOCK_BusClk);
SPI_MasterInit(SPI1, &Mconfig, srcFreq);    //initialising

transfer.dataSize = BUFFER_SIZE;
transfer.rxData = destBuff;
transfer.txData = srcBuff;
transfer.flags = SPI_GetStatusFlags(SPI1);
SPI_MasterTransferBlocking(SPI1, &transfer);

Can you help me that problem and explain how the function works, when it is available?

I saw also that code, but sadly not helped.

 

2) When I made a new project with SDK v2.x, I got errors with unclaired variables.

SIM->SOPT5 = ((SIM->SOPT5 &
(~(SIM_SOPT5_UART0TXSRC_MASK))) /* Mask bits to zero which are setting */
| SIM_SOPT5_UART0TXSRC(SOPT5_UART0TXSRC_UART_TX) /* UART 0 transmit data source select: UART0_TX pin */
);

I changed it like that from a example.

SIM->SOPT5 = ((SIM->SOPT5 &
(~(SIM_SOPT5_LPUART0TXSRC_MASK))) /* Mask bits to zero which are setting */
| SIM_SOPT5_LPUART0TXSRC(SOPT5_UART0TXSRC_UART_TX) /* UART 0 transmit data source select: UART0_TX pin */
| SIM_SOPT5_LPUART0RXSRC(SOPT5_UART0RXSRC_UART_RX) /* UART 0 receive data source select: UART0_RX pin */
);

But I am not sure, whether it is also right. 

Which function has this variable and what should I check or mind when I want to change the variables?

 

Have a nice sunday!

0 件の賞賛
1 解決策
2,231件の閲覧回数
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

 

Receiving the 255 could mean that the SPI module is not connected properly, if you are using SPI1 you need to change the pins from the example to match the corresponding ones from SPI0. I suggest you use SPI0 with the pins indicated in the file readme.txt from the doc folder in the example.

SPI_MasterTransferBlocking transfer a block of data using the polling method, you will exit that function once the transfer was done.

I suggest you to delete the line "transfer.flags = SPI_GetStatusFlags(SPI1);"

 

2) These are masks for the registers on the device, these masks match with the fields name in the register. Under chapter 12.3.5 you can find the mask which they make reference https://www.nxp.com/docs/en/reference-manual/KL27P64M48SF6RM.pdf.

These masks are in the file MKL27Z644.h

 

Let me know if this is helpful, if you have more questions do not hesitate to ask me.

Best regards,

Omar

元の投稿で解決策を見る

2 返答(返信)
2,232件の閲覧回数
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

 

Receiving the 255 could mean that the SPI module is not connected properly, if you are using SPI1 you need to change the pins from the example to match the corresponding ones from SPI0. I suggest you use SPI0 with the pins indicated in the file readme.txt from the doc folder in the example.

SPI_MasterTransferBlocking transfer a block of data using the polling method, you will exit that function once the transfer was done.

I suggest you to delete the line "transfer.flags = SPI_GetStatusFlags(SPI1);"

 

2) These are masks for the registers on the device, these masks match with the fields name in the register. Under chapter 12.3.5 you can find the mask which they make reference https://www.nxp.com/docs/en/reference-manual/KL27P64M48SF6RM.pdf.

These masks are in the file MKL27Z644.h

 

Let me know if this is helpful, if you have more questions do not hesitate to ask me.

Best regards,

Omar

2,207件の閲覧回数
itr1718
Contributor III

Hello

 

I think I set right following my document. But the result is still 255.

In the document, SPI1_SS is connected on PTD6 and programmed direct as GPIO pin.

SPI1_CLK is connected on PTC3. SPI1_MOSI is on PTB16 and SPI1_MISO on PTD7.

So I set like below and added codes for SPI1_SS with the function, GPIO_WritePinOutput. 

 

Are there some not correct codes? Did I understand wrong?

I didn't write the function for SPI1_SS, PORT_SetPinMux, in pin_mux.c. Nevertheless, should I set the pin as default?

 

In pin_mux.c

 //SPI1_SCLK, PTC3
PORT_SetPinMux(PORTC, 3U, kPORT_MuxAlt2);
//SPI1_MOSI, PTB16
PORT_SetPinMux(PORTB, 16U, kPORT_MuxAlt2);
//SPI1_MISO, PTD7
PORT_SetPinMux(PORTD, 7U, kPORT_MuxAlt2);

 

In main.c for transfer

GPIO_WritePinOutput(GPIOD, 6U, 0); //PTD6, SPI1_SS

rslt = SPI_MasterTransferBlocking(SPI1, &spi_transfer);

GPIO_WritePinOutput(GPIOD, 6U, 1); //PTD6, SPI1_SS

0 件の賞賛