Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Help with bit banged spi

2013-11-26 by Philippe Habib

I'm needing to do a bit banged SPI master using an 8051 variant from Silabs and I don't think I'm doing the best thing I could be to get a bit out the port.  I don't think I'm doing the best job to figure out if a bit is high or low, then send it out the port.  I'd appreciate it if someone could suggest a faster way.

I can wiggle the clock at 12.5Mhz, but it takes me 1.1us to do the shift/mask/set to get the next bit of data out, which limits my SPI rate to less than 1 MHz.  I'd like to do 10x that, but I'd settle for 5x.

Here is my code:

	for(j=0;j<Num;j++)
	{
    	for(i=0;i<8;i++)
		{
			Tmp = (((SPIOutBuf[j]<<i) & 0x80)>>7);
			//Tmp = ((SPIOutBuf[j]>>i) & 0x01);
			if(Tmp == 1)
				P4 |= Tmp;	
			else
				P4 &= 0;
			SPICLK = 1;
			SPICLK = 0;
		}
	}


Thank you.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.