Hi,

I think there are two problems with the code:
- using 16 bit data
- shifting by a variable number of bits
An optimization would be to write a funktion which only shifts up to 8 bit, and to shift the data every time by one bit.

Regards,
Nils

original code:

void write_data (Word towrite, Byte nbits)
{
 Byte n;

 for(n = 0; n < nbits; n++)
 {

   CLK_HIGH;
   if( towrite & (0x0001 << n))
   {
     SDIO_HIGH;
   }
   else
   {
     SDIO_LOW;
   }
   CLK_LOW;

 }
}
my version:

void write_data_byte (Byte towrite, Byte nbits)
{
 while(nbits--)
 {
   CLK_HIGH;
   if (towrite&0x01)
   {
     SDIO_HIGH;
   }
   else
   {
     SDIO_LOW;
   }
   CLK_LOW;
   towrite = towrite>>1; // shift by constant value
 }
}

void write_data (Word towrite, Byte nbits)
{
 if (nbits>8)
 {
   write_data_byte((Byte)towrite, 8);
   write_data_byte((Byte)(towrite>>8), nbits-8);
 }
 else
 {
   write_data_byte((Byte)towrite, nbits);
 }
}



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to