MQX SPI

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
1,548 Views
MQXuser
Contributor III

Is there an instruction to write and read the output of a device at the same time?

Because if I use the instructions separately I miss the data I am trying to get. I am using MQX 3.3.

 

Regards

0 Kudos
Reply
1 Solution
440 Views
PetrM
Senior Contributor I

Yes, there are 2 ways:

 

1) MQX 3.3 - Open SPI driver with full duplex flag and everytime you call read it will send the byte from given buffer and receive byte into same position in the buffer:

 

   spifd = fopen ("spi0:", (pointer)(SPI_FLAG_FULL_DUPLEX))

   buffer[0] = BYTE_TRANSMITTED;

   result = fread (buffer, 1, 1, spifd);

   // buffer[0] == BYTE_RECEIVED;

 

2) MQX 3.4 - Use ioctl, which always works regardless on opening mode:

 

   SPI_READ_WRITE_STRUCT  rw;
   rw.BUFFER_LENGTH = 10;
   rw.WRITE_BUFFER = (char_ptr)send_buffer;
   rw.READ_BUFFER = (char_ptr)recv_buffer;
   ioctl (spifd, IO_IOCTL_SPI_READ_WRITE, &rw);

PetrM

 

View solution in original post

0 Kudos
Reply
1 Reply
441 Views
PetrM
Senior Contributor I

Yes, there are 2 ways:

 

1) MQX 3.3 - Open SPI driver with full duplex flag and everytime you call read it will send the byte from given buffer and receive byte into same position in the buffer:

 

   spifd = fopen ("spi0:", (pointer)(SPI_FLAG_FULL_DUPLEX))

   buffer[0] = BYTE_TRANSMITTED;

   result = fread (buffer, 1, 1, spifd);

   // buffer[0] == BYTE_RECEIVED;

 

2) MQX 3.4 - Use ioctl, which always works regardless on opening mode:

 

   SPI_READ_WRITE_STRUCT  rw;
   rw.BUFFER_LENGTH = 10;
   rw.WRITE_BUFFER = (char_ptr)send_buffer;
   rw.READ_BUFFER = (char_ptr)recv_buffer;
   ioctl (spifd, IO_IOCTL_SPI_READ_WRITE, &rw);

PetrM

 

0 Kudos
Reply