Microchip examples for SPI

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Francis
Registered User
Registered User
Posts: 314
Joined: Sun Mar 25, 2007 9:40 am
Location: Devon

Microchip examples for SPI

Post by Francis » Sun Nov 23, 2008 8:37 pm

I'd be really grateful if someone could point me towards an easy-to-read C reference so I can convert some examples in a Microchip datasheet into Swordfish. My knowledge is sadly lacking.

Examples like this:-

Code: Select all

BYTE GetShortRAMAddress(BYTE address)
{
   BYTE toReturn;
   CSn = 0;
   SPIPut((address<<1)&0b01111110);
   toReturn = SPIGet();
   CSn = 1;
   return toReturn;
}
and this:-

Code: Select all

BYTE GetLongRAMAddress(WORD address)
{
   BYTE toReturn;
   CSn = 0;
   SPIPut(((address>>3)&0b01111111)|0x80);
   SPIPut(((address<<5)&0b11100000));
   toReturn = SPIGet();
   CSn = 1;
   return toReturn;
}

These are my feeble attempts, do you think they're miles out?

Code: Select all

Function GetShortRAMAddress(pAddress As Byte) As Byte
    CSn=0
    SPI.WriteByte((pAddress<<1) And %01111110)
    result = SPI.ReadByte()
    CSn=1
End Function

Code: Select all

Function GetLongRAMAddress(pAddress as word) as Byte
    CSn=0
    spi.writebyte(((pAddress>>3) and %01111111)or $80)
    spi.writebyte(((pAddress<<5) and %11100000))
    result = spi.readbyte()
    CSn=1
end function
Thanks in advance.
These are my first dabblings in SPI.
I couldn't find any examples in the SF folder and I was really hoping for a Tutorial....

Post Reply