Hi Philippe,
Can you try the following and see if it gives you a bit more speed?
j = 0;
while( j < Num )
{
i = 0;
while( i < 8 )
{
P4 = ( *(SPIOutBuf + j) & 0x80 ? P4 |1 : 0 );
*(SPIOutBuf + j ) <<=1;
SPICLK = 1;
SPICLK = 0;
++i;
}
++j;
}
If the above gives a bit more speed gain, there is one more trick you can apply in the inner while loop. Simply get rid of the loop and write the process 8 times. That will cost you a bit more in terms of code but because the loop overhead will be eliminated, you should see some significant speed gains.
Let me know how it goes. Good luck!
Regards,
Cagri
________________________________
From: Philippe Habib <phabib@well.com>
To: AVR-Chat@yahoogroups.com
Cc: avr-chat@yahoogroups.com
Sent: Tuesday, 26 November 2013, 8:02
Subject: Re: [AVR-Chat] Help with bit banged spi
I got it to 1.1MHz from 900k by doing this instead.
for(j=0;j<Num;j++)
{
for(i=0;i<8;i++)
{
if(SPIOutBuf[j] & 0x80)
P4 |= 1;
else
P4 &= 0;
SPIOutBuf[j] <<=1;
SPICLK = 1;
SPICLK = 0;
}
}
Does anyone see any big improvement I've missed?
----- Original Message -----
From: "Philippe Habib" <phabib@well.com>
To: avr-chat@yahoogroups.com
Sent: Monday, November 25, 2013 9:48:31 PM
Subject: [AVR-Chat] Help with bit banged spi
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.
------------------------------------
Yahoo Groups LinksMessage
Re: [AVR-Chat] Help with bit banged spi
2013-11-26 by Cagri Tanriover
Attachments
- No local attachments were found for this message.