renee straney

MCF52233   Bit banging

Discussion created by renee straney on Mar 26, 2009
Latest reply on Mar 30, 2009 by Rich Testardi
I have written the following code and captured the output on a logic analyzer.  
Basically I am just sending 32 1s and then the value in "data1" bit by bit.

It works, but slower than I hoped.  Look at the line with the comment "// rising edge of clock".  If I capture that rising edge of the clock on my logic analyzer and measure the time between concurrent rising edges I get

1170 ns.

The 32 1s have a period of 460ns.  I would love to speed that up too if possible.


If found that
if(+( (data1 << j) & 0x80000000))

runs faster than
bit = ( (data1 << j) & 0x80000000);
if (bit == 0x80000000)

The latter had a 1230 ns period


1170 ns is still very slow considering that the receiving device can handle a period of 80ns.  

I don't expect to hit 80ns but I do hope to beat 1170 ns.
 

Does anyone have any suggestion to speed up this parallel to serial bit banging?  
Is there any sample assembly for the MCF5223X that does this?  



 

 

 

void phy_write(unsigned int phy, unsigned int reg, unsigned int data)
{
unsigned    int i,data1,data2,j,bit;

    data1 = 0x50000000;
    data1 = data1 + (phy << 23);
    data1 = data1 + (reg << 18);
    data1 = data1 + 0x00020000;
    data1 = data1 + data;
// send 32 1s
    for(i=0;i<32;i=i+1)
    {
        MCF_GPIO_PORTTC = 0x02;
           MCF_GPIO_PORTTC = 0x03;
    }
// send data    
    for(j=0;j<=31;j=j+1)           
    {                              
        //bit = ( (data1 << j) & 0x80000000);
      //if (bit == 0x80000000)
        if(+( (data1 << j) & 0x80000000))
        {
            MCF_GPIO_PORTTC = 0x02;
        }
        else
        {
             MCF_GPIO_PORTTC = 0x00;             
        }
        MCF_GPIO_PORTTC = MCF_GPIO_PORTTC + 0x01;  // rising edge of clock       
          MCF_GPIO_PORTTC = MCF_GPIO_PORTTC & 0x02;  // falling edge of clock       
    }
}

Outcomes