I’m new to QNX and currently, i need to write some functions to send and receive data using the SPI driver. From the help files, i have saw some functions in the API library like spi_open(), spi_read and spi_write().
The problem is i cannot find the hw/spi-master.h when i install QNX momentics IDE. For your info, i’m using MPC5200 and i have already added the SPI driver from QNX into my project.
Anyone can point me to where i can get hold of spi-master.h file and are there any sample codes on using the SPI where i can reference to?
Hello Kiddocoo,
The hw/spi-master.h header is a part of BSP (board support package).
You have mentioned that you “added the SPI driver from QNX into my projectâ€
Thanks for the reply, i’m currently using generic open(), read() and write() function for SPI.
I’m trying to write to an SPI EEPROM and using an oscilloscope, i can see all the signals but i just cannot read back the return value using read() function. Below is my implementation, please help me to see if there is anything wrong with it. Thanks.
uint8 tx[4];
uint8 data;
fd = open("/dev/spi0", O_RDWR);
tx[0] = 0x03; // read command
tx[1] = 0x00; // address
tx[2] = 0x00; // address
tx[3] = 0xFF; // generate clock pulse to clock in the receive data
write(fd, buf, 4);
read(fd, &data, 1); // the return value here is always 0x00
Hello kiddocoo,
Some details on SPI HW protocol.
In SPI protocol there are at least 4 lines:
ground (ofcourse)
Rx
Tx
Clock
The SPI HW level protocol is Full-Duplex, Master-Slave protocol.
On the same clock tick both the master and the slave sends a bit. which means after the mater transmit a byte, it has a byte from the slave.
Now to refer to your problem.
I think you migth try the following code:
//----------------------- Start Test
uint8 tx[4];
uint8 data[4];
uint i;
fd = open("/dev/spi0", O_RDWR);
tx[0] = 0x03; // read command
tx[1] = 0x00; // address
tx[2] = 0x00; // address
tx[3] = 0xFF; // generate clock pulse to clock in the receive data
for (i = 0 ; i < 4 ; i++)
{
write(fd, &tx[i], 1);
read(fd, &data[i], 1);
}
//----------------------- End Test
And see.
Maybe the driver stops on the first byte received?
can yuo find 0x00 on your oscilloscopes wave forms? is 0x00 a garbage?
Thanks for the help, i have managed to get the SPI working now.
The 0x00 is actually from the buffer from the previous transmit
Meaning i need to read back 5 bytes of data and the correct one is in the 5th byte.
If anyone needs woking SPI codes, i’ll be glad to share it out
I am working on TSC2046 on OMAP platform. The communication to this chip is done over SPI. I have to use spi_open() and spi_xchange() calls to send the control byte and read the converted data.
hey, im new to QNX too
im having the same trouble with spi-master.h. qnx.com/developers/articles/inst_2434_2.html did not help.
can any one of you guys give me directions and sample code for loopback testing on SPI ?
im using BeagleBoard
I am new in the QNX environment. I am writing the SPI driver for our target. But I am confused with the documentation (qnx.com/developers/docs/6.3. … rview.html).
There are two sections 1. Hardware interface and 2. API library.
To write the SPI driver, what should I need to Implement?
1.Do I need to implement hardware specific functions which are given in “spi_funcs_t;“ ?
OR
2.Do I need to implement API library e.g. spi_open, spi_close, spi_setcfg etc?
In case if I need to implement only “spi_funcs_tâ€
I am trying to use the SPI to communicate with a peripheral sensor device. Would you mind sharing your modified SPI code with me? My email is eric.dongxx@gmail.com. Thanks a lot!