eren-terzioglu commented on issue #13855:
URL: https://github.com/apache/nuttx/issues/13855#issuecomment-2411582761
> Hello @eren-terzioglu
>
> below you can see an example:
>
> ```
> #include <nuttx/config.h>
> #include <stdio.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include <errno.h>
> #include <string.h>
> #include <stdlib.h>
>
>
/****************************************************************************
> * Public Functions
>
****************************************************************************/
>
> #define MASTER 0
>
> #ifdef MASTER
> #define SOURCE_FILE "/dev/spi2"
> #else
> #define SOURCE_FILE "/dev/spislv2"
> #endif
> #define BUFFER_SIZE 256
>
>
/****************************************************************************
> * hello_slave_main
>
****************************************************************************/
>
> int main(int argc, FAR char *argv[])
> {
> int fd;
> char buffer[BUFFER_SIZE];
> ssize_t bytes_read;
>
> printf("Slave started!!\n");
> fd = open(SOURCE_FILE, O_RDWR);
>
> if (fd < 0)
> {
> printf("Failed to open %s: %s\n", SOURCE_FILE, strerror(errno));
> return 0;
> }
>
> while(1)
> {
> // Read the number from the source file
> printf("Slave: Reading from %s\n", SOURCE_FILE);
> bytes_read = read(fd, buffer, BUFFER_SIZE - 1);
>
> if (bytes_read < 0)
> {
> printf("Failed to read from %s: %s\n", SOURCE_FILE,
strerror(errno));
> close(fd);
> return 0;
> }
> else if (bytes_read > 0)
> {
> buffer[bytes_read] = '\0';
> printf("Slave: Read value '%s' from %s\n", buffer, SOURCE_FILE);
>
> // Write the same value back
> printf("Slave: Writing value '%s' back to %s\n", buffer,
SOURCE_FILE);
> if (write(fd, buffer, strlen(buffer)) < 0)
> {
> printf("Failed to write to %s: %s\n", SOURCE_FILE,
strerror(errno));
> close(fd);
> return 0;
> }
> }
>
> sleep(1);
> }
>
> close(fd);
> return 0;
> }
> ```
>
> In this example I am always answer empty buffer to master, but you will
see that the master will print data. If you have one available, please use a
logic analyzer.
Thanks, I am checking with a logic analyzer too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]