Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Please check my SPI bus pseudo code

Status
Not open for further replies.

techie

Advanced Member level 3
Joined
Feb 5, 2002
Messages
839
Helped
58
Reputation
116
Reaction score
9
Trophy points
1,298
Location
Pakistan
Activity points
7,805
SPI bus question

I am implementing the SPI bus in software. Can someone pls verify the psuedo code below. Somehow my code is not working.

Code:
CS = 0

loop 8 times
{
  output bit on SI
  CLK = 1
  read bit on SO
  CLK = 0
}

CS = 1;
 

Re: SPI bus question

hi techie

First you shoud ensure weather you are going to implement hardware SPI stack or Sortware.I think you expect Software only!!!.Also you shoud know CLOCK polority,Clock phase..

To write a byte
fun(byte data)
{
CS = 0; //Chip Enable
loop 8 times,
{
SCLK = 1;
Delay(3);
SO = (data >> 7);
Delay(3);
SCLK = 0;
data <<= 1;
}
CS = 1; //Chip Disable


}
 

    techie

    Points: 2
    Helpful Answer Positive Rating
SPI bus question

The difference in my and your code is that I am writing and reading the serial data one clock edge earlier. Can you you point to some reference notes.

The delay should not be needed since my peripheral is ENC28J60 which has a 10MHz SPI bus. My controller has only 2MHz clock.
 

Re: SPI bus question

hi techie

May i know your controller?..Also try with different possiblities(usually I do the same) like put delay and without.
 

SPI bus question

I am using Philips P89C51RD+. It is a standard 8051 part. The SPI device is much faster than the 8051 so I didnt put any delays.
 

SPI bus question

hi

for SPI lot of referenceses available but no idea about your controller.any have go through PIC you may get general idea.(h**p://www.microchipc.com/sourcecode/#interface)

Your peripherial ENC28j20 accept only raising edge datas.So make sure that!
 

SPI bus question

in avr it is possible to play with clock edges and timing. I suppose it is just a mean to support various devices which could act similar to spi . f.e. 74hc595. So what clock edge to use is dependednt on actual spi slave you are going to have connection with.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top