Slow Software SPI

Writing software for systems that use VLSI Solution's devices as slave codecs to a host microcontroller.
Brek
Senior User
Posts: 47
Joined: Sun 2016-09-11 5:51

Slow Software SPI

Postby Brek » Wed 2017-05-10 5:25

Hi Guys,
This is a slow software SPI for any microcontroller, for use in testing,
or permanently for use an application before initially setting the VSxxxx clock speed.
delay_gen is a delay function that could be filled with extra delay to make it slower, but as it is, it can run with a 40MIPS micro,
and is slow enough as it is to initially talk to a VLSI Solutions VSxxx chip with 12.xxMHz clock before having applied any clock settings.

Microchip have some examples in SD card library where they do the same in a verbose fashion,
but since it’s supposed to be slow, it might as well be wrapped in a loop (so this is not the fastest SPI that software could do).
Now this one is entirely my own, free from any Copyright, and It’s given up to the public domain.

Code: Select all

//
unsigned char WriteSPIManual(unsigned char data_out) {
unsigned char i = data_out;
int spirotcnt = 0;
SPICLOCKLAT = 0; SPIOUTLAT = 0;
while (spirotcnt < 8) {
SPICLOCKLAT = 0;
if (i & 0x80) {SPIOUTLAT = 1;} else {SPIOUTLAT = 0;}
delay_gen(); SPICLOCKLAT = 1;
delay_gen(); spirotcnt++; i = i << 1;
} // spirotcnt
SPICLOCKLAT = 0; SPIOUTLAT = 0;
return 0;
}
//
//
//
unsigned char ReadSPIManual (void) {
unsigned char result = 0x00;
int wspirotcnt = 0;
SPICLOCKLAT = 0; SPIOUTLAT = 0;
while (wspirotcnt < 8) {
result = result << 1;
SPICLOCKLAT = 0; delay_gen();
SPICLOCKLAT = 1; delay_gen();
if (SPIINPORT == 1) {result |= 0x01;}
wspirotcnt++;
} // wspirotcnt
SPICLOCKLAT = 0;
return result;
}
//
//
//
void delay_gen() {return;}
//

Return to “Microcontroller Software”

Who is online

Users browsing this forum: No registered users