Yeah spikey 30 ticks is the proper delay but I thought as you said that all the other calculations that the processor will be doing will compensate for it one way or the other. Ofcourse ... in the datasheet it says 250ns minumum, so I guess it is all the same
Anyway, I managed to write to the sensor with the blackfin now. Could turn it from awake mode to sleep mode and back by writting to its configuration register. When I tried to read from it I had some problems though. So I want to ask somethings.
The datasheet mentions that we need to go to Hi-Z state after the last address bit. Isn't HI-Z state just going to input mode?
Here is the code:
Code:u8 opticalRead(u8 rAddr)
{
int i = 0 ;
u8 data = 0x00;
//we make sure the address has '0' as its MSB
rAddr &= ~0x80;
//we send the register's address
for(i=8;i>=1;i--)
{
if(isSet(rAddr,i-1))
raiseData();
else
lowerData();
lowerClock(); //SDA is changed on falling edges of the clock
delay(30);
raiseClock(); //and the sensor reads it on rising edges
delay(30);
}
//we go to Hi-Z state
*pPORTHIO_DIR &= ~0x8000;
*pPORTHIO &= ~0x8000;
*pPORTHIO_INEN |= 0x8000;
delayMS(100); //wait 100 microsecond
for(i=8;i>=1;i--)
{
lowerClock();//SDA is changed on falling edges of the clock
if(*pPORTHIO & 0x8000)
setBit(data,i-1);
else
clearBit(data,i-1);
delay(30);
raiseClock();
delay(30);
}
*pPORTHIO_INEN &=~0x8000; //back to output
*pPORTHIO_DIR |= 0x8000;
return data;
}
The send address part of the function should be working 100% since it is the same as the opticalWrite function's. Problem is no matter which register I try to read I get an 0xFF byte. Which means that :
if(*pPORTHIO & 0x8000) is always true. So it means that either the sensor does not send the data or it does but the microcontroller does not recognize them since PH15 is always at logical high.
Maybe the way I go HI-Z state is wrong? Or should I set the polar/edge/both too? But I think the default value logical high reads as 1 and logical low as 0 is what I need, right?