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.

[SOLVED] SPI write routine for a array

Status
Not open for further replies.

treyz

Member level 5
Joined
Sep 26, 2012
Messages
93
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,065
Hi,

I am looking for a SPI WRite routine for an array.
I know how to do it for a bit but I am struggling with an array.

Can have some help?Please
 

It depends upon the device to which you are communicating via SPI bus ,Some devices need proper clock transition at their CS pin before doing SPI write,and there could be any other proper sequence to do it,and you may be knowing that inorder to read data on SPI bus you first need to write some data.I have tried it with the below function to communicate with an SD card :


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
char spi_write(char byte)
{int i;
 //sclk=0;
 for(i=0;i<8;i++)
 { 
  
  sclk=0;
  if(byte&0x80)
  MOSI=1;
  else
  MOSI=0;
 
  byte=byte<<1;
  byte=byte|MISO;
 
  sclk=1; 
  DelayUs(5);
 
 
 }
 
 return byte;
}


you can call this function multiple times if multiple data is needed to be sent...
 
Last edited by a moderator:

Hi,

Thank you for replying to me.

I am trying to establish a communication between two PIC(18f4680) and I am using C18 compiler.

Is that still compatible with your piece of code?
 

In my opinion as this is a driver code hence it will work with any controller having simply GPIOs,you just need to define port pins with their purpose in the bus like by using #define statements and define MOSI,MISO,SCLK and CS.
but i think you can use the SPI peripheral already available in the pic that you have mentioned,i was actually mistaken since you asked for a routine...
 

Thank you

I think I see where you are coming from.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top