SPI Driver

Hi,

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?

Thanks.

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â€

Hi Yuriy,

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:

  1. ground (ofcourse)
  2. Rx
  3. Tx
  4. 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.

  1. Maybe the driver stops on the first byte received?
  2. can yuo find 0x00 on your oscilloscopes wave forms? is 0x00 a garbage?

Hi RanAricha,

Thanks for the help, i have managed to get the SPI working now.
The 0x00 is actually from the buffer from the previous transmit :frowning:
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 :slight_smile:

Regards,
Kiddo

Can u send me ur working SPI codes including driver and test application. And my email is xu_wang@hirain.com.

Many thanks

王旭(i’m chinese)

Can you please send me the SPI code.

Thanks,
Sumanth

Hi kiddocoo,
iam a begginer in QNX.iam going to write SPI controller driver for samsung S3C2410 board.

  • is it spi controller driver and spi driver same?
  • can u tell me what are the things i have to study before coding.?
  • From where can i get the BSP of s3c2410?

I am expecting ur reply,It’s very urgent for my career.

Advanced Thanks
Sunil

Hi Kiddocoo,

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.

Can u share your SPI code for reference?

Thanks and Regards,
Sakshar

Hi Kiddocoo,

I am working on the SPI controller driver for MPC8360E-RDK board. I am wondering if you could share me with your driver and test program code.

Thanks,
Jew-Dong

jdkuo@multibeamcorp.com

would you please send me the code that you have writen. soare.sorinhoratiu@gmail.com is my more frequently used address. thanks

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â€

Hi Kiddo,

Would appreciate if you can share the spi working code. I know it is very old thread, but just in case if you have backed it up ;).

I am working on TSC2046 touch controller on OMAP platform.

Raj (m.raj.pandey@gmail.com)

Hi ,
I am currently working on SPI driver test for OMAPl138.
My application is like this:
const char * path = “/dev/spi0”;

int main(int argc, char *argv[]) {

int dev,fd,i;
dev = SPI_DEV_ID_NONE;
fd = spi_open(path);
spi_devinfo_t *devinfo;
int len =1;
uint8_t buf[1], buf1[1];
buf[0] = 55;
if(fd<0)
{
	fprintf(stderr, "SPI open failed, fd = %d errno = %d\n", fd, errno);
	strerror(errno);
	return(-1);
}
devinfo->device = SPI_DEV_ID_NONE;

devinfo->cfg.clock_rate = 150000000;
i = spi_getdevinfo(fd, dev, devinfo);
if (i==0)
{
	printf("success");
	while(1){
			spi_xchange(fd, dev, buf, buf1, len);
			printf("done");
		}
}
else
	printf("fail");
spi_close(fd);
return EXIT_SUCCESS;

}
I am getting error as memory fault .

Please help me test the driver with SPI application.

–Zaheer.

Zaheer,

What do you mean you are getting error as a memory fault.

Do you mean your program crashes? If so, run the debugger and see where.

If you mean you get an error code it would help to know what it is.

Tim

Dear Kiddo,

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!

Best regards,
Eric

Hi
I have new queries in compiling the Resource Manager driver for i2c. Following are my queries for writing new resource manager

  1. Whether the project for writing new resource manager(RM) should be created as static/shared?
  2. After the compiling the RM driver, where to copy .o/.so/*.a ?
  3. Should I change any makefiles?

RIght now I using Momentics 6.5 IDE, please share the procedure in compiling and updating the IFS for writing new RM driver.
Looking for suggestions.