Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy does ioctl return "bad address"
    primarykey
    data
    text
    <p>I use the the code below to output data from SPI port of an embedded board (olimex imx233-micro -- it is not a board specific question). When I run the code <code>ioctl</code> return "<strong>bad address</strong>". I am modifying the code on <a href="http://twilight.ponies.cz/spi-test.c" rel="nofollow">http://twilight.ponies.cz/spi-test.c</a> which works fine. Could anyone tell me what am I doing wrong?</p> <pre><code>root@ubuntu:/home# gcc test.c -o test test.c:20: warning: conflicting types for ‘msg_send’ test.c:16: note: previous implicit declaration of ‘msg_send’ was here root@ubuntu:/home# ./test errno:Bad address - cannot send SPI message root@ubuntu:/home# uname -a Linux ubuntu 3.7.1 #2 Sun Mar 17 03:49:39 CET 2013 armv5tejl GNU/Linux </code></pre> <p>Code:</p> <pre><code>//test.c #include &lt;stdint.h&gt; #include &lt;unistd.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;getopt.h&gt; #include &lt;fcntl.h&gt; #include &lt;sys/ioctl.h&gt; #include &lt;linux/types.h&gt; #include &lt;linux/spi/spidev.h&gt; #include &lt;errno.h&gt; static uint16_t delay; int main(int argc,char *argv[]){ msg_send(254); //the message that I want to send decimal "254" return 0; } void msg_send(int msg){ int fd; int ret = 0; fd = open("/dev/spidev32766.1", O_RDWR); //ls /dev outputs spidev32766.1 if(fd &lt; 0){ fprintf(stderr, "errno:%s - FD could be not opened\n ", strerror(errno)); exit(1); } struct spi_ioc_transfer tr = { .len = 1, .delay_usecs = delay, .speed_hz = 500000, //500 kHz .bits_per_word = 8, .tx_buf = msg, .rx_buf = 0, //half duplex }; ret = ioctl(fd, SPI_IOC_MESSAGE(1), &amp;tr); if (ret &lt;1 ){ fprintf(stderr, "errno:%s - cannot send SPI message\n ", strerror(errno)); } close(fd); } </code></pre> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload