SPI0 fail with Framesize = 16

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

SPI0 fail with Framesize = 16

Jump to solution
870 Views
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

Labels (3)
1 Solution
597 Views
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

View solution in original post

7 Replies
597 Views
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 Kudos
597 Views
karina_valencia
NXP Apps Support
NXP Apps Support

MQX

0 Kudos
597 Views
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 Kudos
597 Views
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 Kudos
598 Views
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

597 Views
sandrobastos
Contributor IV

Hi Juan,

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

thank you very much.

cheers

597 Views
karina_valencia
NXP Apps Support
NXP Apps Support

juangutierrez please review  this  case and provide follow up.