SPI0 fail with Framesize = 16

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

SPI0 fail with Framesize = 16

跳至解决方案
889 次查看
sandrobastos
Contributor IV

Hi,

I'm trying to set my SPI0 to 16 bits through:

// Framesize = 16
param = 16;
printf ("Changing the Framesize to %d bits ... ", param);
if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_SET_FRAMESIZE, &param))
{
printf ("OK\n");
}
else
{
printf ("ERROR\n");
}

The procedure is accepted and I receive an OK and read 16 when a GET_FRAMESIZE is issued.

The problem is I cannot write at the device; it always returns error, only with 16 bits, if 8 is set, it works fine.

How can I work with SPI in 16 bits?

Thank you...BrunoCastelucci

标签 (3)
1 解答
616 次查看
juangutierrez
NXP Employee
NXP Employee

Hi Sandro

Glad to hear you get it working.

Not sure, but the error might be because the fputc is intended for writing just one character (1 byte) to the stream.

Maybe you want to try using fputs instead, and sending a two-character string.

Let us know if that works.

Thanks

juan gutierrez

在原帖中查看解决方案

7 回复数
616 次查看
juangutierrez
NXP Employee
NXP Employee

Is this Linux or MQX?

Are both slave and master devices configured for 16bits?

Is it possible to share your application test and a way to test it in our side?

0 项奖励
616 次查看
karina_valencia
NXP Apps Support
NXP Apps Support

MQX

0 项奖励
616 次查看
juangutierrez
NXP Employee
NXP Employee

Can you post which function are you calling for writing to the device and what kind of error you get, please?

0 项奖励
616 次查看
sandrobastos
Contributor IV

Hi Juan,

Thanks for replying.

I'm using MQX. Yes, the slave is 16 bits; it's an LCD display.

I'm using 'fputc(data, spifd)' to write the data and, when configured to 16 bits, I get an IO_ERROR (-1) and nothing happens on the SDA, SCL, lines.

The fputc() enables de CS to the device and 'fflush()' disables it.

I solved the problem by sending two bytes (2 x fputc()) and then 'fflush()', this way the CS is only disabled after 16 bits is transmitted.

Anyway, I think the SPI should work fine at 16 bits.

Thanks and regards.

0 项奖励
617 次查看
juangutierrez
NXP Employee
NXP Employee

Hi Sandro

Glad to hear you get it working.

Not sure, but the error might be because the fputc is intended for writing just one character (1 byte) to the stream.

Maybe you want to try using fputs instead, and sending a two-character string.

Let us know if that works.

Thanks

juan gutierrez

616 次查看
sandrobastos
Contributor IV

Hi Juan,

You are right, I changed fputc by fwrite and it's working fine!

thank you very much.

cheers

616 次查看
karina_valencia
NXP Apps Support
NXP Apps Support

juangutierrez please review  this  case and provide follow up.