Skip navigation.
Home
The QNX Community Portal

View topic - SPI Driver

SPI Driver

For discussion of realtime and/or embedded programming.

SPI Driver

Postby kiddocoo » Thu Jul 10, 2008 8:51 am

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.
kiddocoo
New Member
 
Posts: 4
Joined: Thu Jul 10, 2008 8:41 am

RE: SPI Driver

Postby ysinitsky » Tue Jul 29, 2008 8:14 pm

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â€
ysinitsky
Senior Member
 
Posts: 164
Joined: Wed Dec 14, 2005 8:46 pm

RE: SPI Driver

Postby kiddocoo » Fri Aug 01, 2008 1:50 am

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
kiddocoo
New Member
 
Posts: 4
Joined: Thu Jul 10, 2008 8:41 am

RE: SPI Driver

Postby RanAricha » Wed Nov 05, 2008 8:30 pm

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?
RanAricha
New Member
 
Posts: 4
Joined: Wed Nov 05, 2008 7:43 pm

RE: SPI Driver

Postby kiddocoo » Thu Nov 06, 2008 1:18 am

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 :(
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 :)

Regards,
Kiddo
kiddocoo
New Member
 
Posts: 4
Joined: Thu Jul 10, 2008 8:41 am

RE: SPI Driver

Postby SunShining » Fri Dec 12, 2008 9:40 am

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)
SunShining
New Member
 
Posts: 1
Joined: Fri Dec 12, 2008 8:59 am

Re: RE: SPI Driver

Postby sumanthv » Wed Mar 18, 2009 9:03 am

kiddocoo wrote: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 :(
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 :)

Regards,
Kiddo



Can you please send me the SPI code.

Thanks,
Sumanth
sumanthv
New Member
 
Posts: 1
Joined: Wed Mar 18, 2009 9:01 am

Re: RE: SPI Driver

Postby sunil.ravi » Fri Mar 20, 2009 5:18 am

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
sunil.ravi
New Member
 
Posts: 3
Joined: Tue Mar 17, 2009 9:45 am

RE: Re: RE: SPI Driver

Postby sakshar » Tue Jun 09, 2009 12:26 pm

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
sakshar
New Member
 
Posts: 6
Joined: Fri May 30, 2008 10:44 am

Will Appreciate for the SPI Driver and Test Code

Postby jewdongkuo » Wed Aug 19, 2009 8:39 pm

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
jewdongkuo
New Member
 
Posts: 7
Joined: Mon Jul 20, 2009 11:03 pm

Request for code

Postby beliver_X » Thu Jan 14, 2010 12:13 pm

would you please send me the code that you have writen. soare.sorinhoratiu@gmail.com is my more frequently used address. thanks
beliver_X
Active Member
 
Posts: 11
Joined: Thu Jan 14, 2010 12:12 pm

RE: Request for code

Postby Zubeen » Wed Feb 03, 2010 2:41 am

hey, im new to QNX too
im having the same trouble with spi-master.h.
http://www.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
Zubeen
New Member
 
Posts: 1
Joined: Wed Feb 03, 2010 2:40 am

query regarding "spi_funcs_t"

Postby vdukandar » Thu Jan 27, 2011 6:57 am

I am new in the QNX environment. I am writing the SPI driver for our target. But I am confused with the documentation (http://www.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â€
vdukandar
New Member
 
Posts: 1
Joined: Thu Jan 27, 2011 6:43 am

Re: RE: SPI Driver

Postby rajp » Tue Mar 08, 2011 8:36 am

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)

kiddocoo wrote: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 :(
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 :)

Regards,
Kiddo
rajp
New Member
 
Posts: 1
Joined: Tue Mar 08, 2011 8:31 am

Re: SPI Driver

Postby zair » Tue Dec 06, 2011 10:24 am

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.
zair
New Member
 
Posts: 1
Joined: Mon Dec 05, 2011 8:56 am

Next

Return to Realtime and Embedded

Who is online

Users browsing this forum: Google [Bot] and 0 guests

cron