# SPI Problems

**URL:** https://forums.digi.com/t/spi-problems/11125
**Category:** Rabbit
**Created:** [September 7, 2009, 8:01am UTC](https://forums.digi.com/t/spi-problems/11125 "2009-09-07T08:01:04Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![newbie](https://avatars.discourse-cdn.com/v4/letter/n/dc4da7/32.png) [@newbie](https://forums.digi.com/u/newbie)
#### Post date: [September 7, 2009, 8:01am UTC](https://forums.digi.com/t/spi-problems/11125/1 "2009-09-07T08:01:04Z")

</div>

Hi,

I m working with this RCM4500 and using this SPI function but it didint seen to work. i read some of the post and notice that the comment was to us Serial B instead of serial C. but i have already use Serial B for my xbee.

## Was serial C not competible for SPI? i used and edited they sample coding given:

#class auto

#define SPI\_SER\_C  
#define SPI\_CLK\_DIVISOR 100

#use “spi.lib”

void main()  
{  
char adc\_reading[2];  
int i;  
int adc\_sample;

```
SPIinit();
while(1)
{
            SPIWrite("\x05", 1); \\ cmd to write to register
   SPIRead(adc_reading, 2);
   printf("SPI bytes = 0x%x 0x%x

```

## ", adc\_reading[0], adc\_reading[1]); } }

I always got a 0xff or 0x00

Or is my pin configuration wrong? Below is my configuration:

PC3 connected to Dout of my SPI component  
PC2 connected to Din of my SPI component  
PD2 connected to SCLK of my SPI component

---

<div class="post-metadata">

### Author: ![sgt](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@sgt](https://forums.digi.com/u/sgt)
#### Post date: [September 7, 2009, 3:39pm UTC](https://forums.digi.com/t/spi-problems/11125/2 "2009-09-07T15:39:15Z")

</div>

What about chip select? I’ve got some devices here that will not work if you just ground /CS…

Haven’t used SPI.LIB myself - I just roll my own - so I can’t speak to that aspect of it. I do use serial port C as an SPI port though (this is on an RCM 5700, not 4500), so there should be no problem there.

Another thing to look at: You haven’t shown your port initialization. Have you set up Serial Port C to map to the pins you are using?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex016/uploads/digi/original/1X/11da31a6a1fbcd03ef21d3f785c317c824009ae2.png) [@system](https://forums.digi.com/u/system)
#### Post date: [November 22, 2009, 6:18am UTC](https://forums.digi.com/t/spi-problems/11125/3 "2009-11-22T06:18:25Z")

</div>

Whyd you need to throw in the part about telling Mike you wouldnt post about this then turn around and did just that?

Ive not had any problems.

---

<div class="post-metadata">

### Author: ![newbie](https://avatars.discourse-cdn.com/v4/letter/n/dc4da7/32.png) [@newbie](https://forums.digi.com/u/newbie)
#### Post date: [September 8, 2009, 9:13am UTC](https://forums.digi.com/t/spi-problems/11125/4 "2009-09-08T09:13:20Z")

</div>

## Thanks for your quite respond. Initalising? To do u mean this?

```
#define SPI_DR	SCDR
#define SPI_CR	SCCR
#define SPI_ShCR	SCCRShadow
#define SPI_SR	SCSR
#define SPI_ER	SCER
#define SPI_ShER	SCERShadow

WrPortI ( SCDHR, NULL, (SPIdivisor&gt;&gt;8) | 0x80 );
WrPortI ( SCDLR, NULL, SPIdivisor &amp; 0xFF );

```

* * *

its defined in the spi library.  
Ok i will connect tthe chipselect and see if it works.

---

<div class="post-metadata">

### Author: ![sgt](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@sgt](https://forums.digi.com/u/sgt)
#### Post date: [September 8, 2009, 4:24pm UTC](https://forums.digi.com/t/spi-problems/11125/5 "2009-09-08T16:24:55Z")

</div>

By initializing, I’m referring to setting up the parallel ports. Like this, which won’t be exactly what you need to do, but should give you the idea:

```auto

   // Parallel Port C Setup
   WrPortI(PCDDR, &amp;PCDDRShadow, (PCDDRShadow &amp; 0xF3) | 0x0C); // PC2 &amp; 3 are outputs
   WrPortI(PCALR, &amp;PCALRShadow, (PCALRShadow &amp; 0xCF) | 0x00); // PC2: Alt out 0 (TxC)
   WrPortI(PCFR, &amp;PCFRShadow, (PCFRShadow &amp; 0xF3) | 0x04); // PC2 alt out, PC3 norm

   // Parallel Port D Setup
   WrPortI(PDDDR, &amp;PDDDRShadow, (PDDDRShadow &amp; 0xF3) | 0x0C); // PD2, 3 are outputs
   WrPortI(PDALR, &amp;PDALRShadow, (PDALRShadow &amp; 0xCF) | 0x00); // PD2: Alt out 0 (SCLKC)
   WrPortI(PDFR, &amp;PDFRShadow, (PDFRShadow &amp; 0xF3) | 0x04); // PD2 alt out, PD3 norm

```

The registers are described in the Microprocessor User’s Manual for whatever processor you are using.

---

<div class="post-metadata">

### Author: ![sam2](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@sam2](https://forums.digi.com/u/sam2)
#### Post date: [October 8, 2009, 10:08am UTC](https://forums.digi.com/t/spi-problems/11125/6 "2009-10-08T10:08:39Z")

</div>

Hi, im also trying out the spi in rabbit, im trying to connect it with a adc, so basically what pins do i need to wired out to the rabbits port…

Vcc to +3.3V  
Gnd to Gnd  
SCLK to SCLKA  
Chip Selection to Any Output Port  
Data out to TxB  
Data In to RxB

is it something like this?
