Hello,
after updating to 3.0b4, the spi2 interface is unfortunately not working.
The program was working proberly on 3.0b3
#define SPI1_MODE 2
#define SPI1_CLK_SPEED 10 * 1000000 //10Mhz
#define SPI1_BITS 8
#define SPI1_DELAY 0
static const char *SPI_dev_name = "/dev/spidev1.0";
uint8_t rxBuffer[2];
uint8_t CONFIG1[2] = {0x40,0x03};
void transferSPI(int fd,struct spi_ioc_transfer* tr, uint8_t const *tx, uint8_t const *rx, size_t len)
{
int ret;
tr->tx_buf = (unsigned long)tx;
tr->rx_buf = (unsigned long)rx;
tr->len = len;
ret = ioctl(fd, SPI_IOC_MESSAGE(1), tr);
if (ret < 1)
{
pabort("can't send spi message");
exit(1);
}
}
int SPI_initialize( const char *dev,struct spi_ioc_transfer *tr,uint32_t mode,uint8_t bits,uint32_t speed,uint16_t delay)
{
int spiFD,ret;
tr->delay_usecs = delay;
tr->speed_hz = speed;
tr->bits_per_word = bits;
if (mode & SPI_TX_QUAD)
tr->tx_nbits = 4;
else if (mode & SPI_TX_DUAL)
tr->tx_nbits = 2;
if (mode & SPI_RX_QUAD)
tr->rx_nbits = 4;
else if (mode & SPI_RX_DUAL)
tr->rx_nbits = 2;
if (!(mode & SPI_LOOP)) {
if (mode & (SPI_TX_QUAD | SPI_TX_DUAL))
tr->rx_buf = 0;
else if (mode & (SPI_RX_QUAD | SPI_RX_DUAL))
tr->tx_buf = 0;
}
spiFD = open(dev, O_RDWR);
if (spiFD < 0)
pabort("can't open device");
// spi mode
ret = ioctl(spiFD, SPI_IOC_WR_MODE32, &mode);
if (ret == -1)
pabort("can't set spi mode");
ret = ioctl(spiFD, SPI_IOC_RD_MODE32, &mode);
if (ret == -1)
pabort("can't get spi mode");
//bits per word
ret = ioctl(spiFD, SPI_IOC_WR_BITS_PER_WORD, &bits);
if (ret == -1)
pabort("can't set bits per word");
ret = ioctl(spiFD, SPI_IOC_RD_BITS_PER_WORD, &bits);
if (ret == -1)
pabort("can't get bits per word");
// max speed hz
ret = ioctl(spiFD, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if (ret == -1)
pabort("can't set max speed hz");
ret = ioctl(spiFD, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
if (ret == -1)
pabort("can't get max speed hz");
printf("spi mode: 0x%x\n", mode);
printf("bits per word: %d\n", bits);
printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);
return (spiFD);
}
void pabort(const char *s)
{
perror(s);
abort();
}
void main()
{
fd_spi1 = SPI_initialize(SPI_dev_name,&spi_tr1,SPI1_MODE,SPI1_BITS,SPI1_CLK_SPEED,SPI1_DELAY);
while(1)
{
transferSPI(fd_spi1,&spi_tr1,(uint8_t *)CONFIG1,(uint8_t *)rxBuffer,2);
usleep(1000);
}
}
I get also kernel oops when the program starts: oops.log
Best regards, Majd