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
Solved! Go to Solution.
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
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