Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-30-2011, 03:30 AM   #1
LQ Newbie
Registered: Nov 2011
Location: Czech Republic
Distribution: Debian derivatives, uClinux and others
Posts: 10

Rep: Reputation: Disabled
Design of a communication protocol over SPI with master/slave switching

Hello all,
I have to implement a communication between two microprocessors using SPI and three GPIOS. The first one is cr16 running uClinux and the second one is arm7 without an OS. The arm7 serves as the main control unit and on the SPI bus there is a flash memory and the cr16 processor - now the problem begins. Arm7 must work as a SPI master for the flash, however cr16 must work as a master too (it does not have support for slave). At first I though I would be able to implement it in userspace using spidev driver, but I was too slow there, so I wrote a simple chardev, which controls the transfers.

Until now I need only to send a messages in the direction from the arm proc. It is done simply - using GPIO1 the arm signals that the SPI bus is free and switches to the slave mode, cr16 claims the bus, generate the clock and chip select, gets data and frees the bus again.
In uClinux an application thread is using blocking ioctl which is waked up by an interrupt on GPIO1.

However now I need also to send a messages from the cr16 to arm. It can be done similarly - cr16 signals there is a message using GPIO2, then the arm signals free bus by GPIO1 and the transfer can be done.

Unfortunately I can't figure out how to correctly deal with this two situations together - I'm waiting on an action on GPIO1 - which signals the message in one direction and in the same time (asynchronously) I need to send the message in another direction and this action also need GPIO1 to know the bus is free...

Can please anyone give me some advice, how to correctly solve this problem? Excuse me if my description is too messy and also the hardware layout is done for now and can't be changed... I'm interested mainly on the solution on cr16 (uClinux) side.

best regards
Old 11-30-2011, 10:34 AM   #2
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
This sounds conceptually similar to the problem of networking devices on a shared media. Some general classes of solution are:
  • Collision detection (like ethernet)
  • Token passing (like token ring)
  • Timed synchronization
Since I don't think the hardware allows for any kind of collision detection, that is probably not workable. Token passing could work, but requires some overhead. Synchronization through timed talk & listen windows also requires some overhead, and is easiest to implement when one node provides some kind of sync signal against which other nodes can synchronize. Each system requires some scheme to establish priority and identity in terms of which node will assume respective roles, but this sounds like a system where it can be built into the application, or has an obvious default.

--- rod.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
About How to SPI slave keep up master jason222333 Linux - Kernel 0 10-11-2010 08:32 PM
MySQL Master-Slave Replication - How to make the slave read-only? saagar Linux - Server 1 08-31-2010 08:13 AM
Communication with SPI driver Mactub Linux - Software 2 03-16-2010 02:17 AM
Dedicated communication between master and slave rani_162 Linux - Networking 1 09-16-2005 02:12 PM
Switching master/slave drives pickarooney Linux - Hardware 11 11-08-2004 01:02 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:19 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration