ales2k » 08 фев 2016, 22:56
Итак не работает этот кусок, подключение верное
while (1) {
temp_byte = ADNS_read(Pixel_Grab);Это отрабатывает
if (temp_byte & Pixel_data_valid) { тут вечный цикл
break;
}
ADNS_read() Всегда возвращает 0. что то с ним не так... будем посмотреть дальше
В то же время простейший код отрабатывает идеально
//-------------------------------------------------------
#define SDIO 12 //значения ставил как у вас и переключал физику, тоже работает.
#define SCLK 10 //
//-------------------------------------------------------
byte DriverRead(byte address)
{
pinMode (SDIO, OUTPUT);
for (byte i=128; i >0 ; i >>= 1)
{
digitalWrite (SCLK, LOW);
delayMicroseconds(10);
digitalWrite (SDIO, (address & i) != 0 ? HIGH : LOW);
delayMicroseconds(10);
digitalWrite (SCLK, HIGH);
delayMicroseconds(10);
}
delayMicroseconds(120);
pinMode (SDIO, INPUT);
byte res = 0;
for (byte i=128; i >0 ; i >>= 1)
{
digitalWrite (SCLK, LOW);
delayMicroseconds(10);
digitalWrite (SCLK, HIGH);
delayMicroseconds(10);
if( digitalRead (SDIO) == HIGH )
{
res |= i;
}
}
delayMicroseconds(100);
return res;
}
//-------------------------------------------------------
void DriverWrite(byte address, byte data)
{
address |= 0x80;
pinMode (SDIO, OUTPUT);
for (byte i = 128; i > 0 ; i >>= 1)
{
digitalWrite (SCLK, LOW);
delayMicroseconds(10);
digitalWrite (SDIO, (address & i) != 0 ? HIGH : LOW);
delayMicroseconds(10);
digitalWrite (SCLK, HIGH);
delayMicroseconds(10);
}
delayMicroseconds(120);
for (byte i = 128; i > 0 ; i >>= 1)
{
digitalWrite (SCLK, LOW);
delayMicroseconds(10);
digitalWrite (SDIO, (data & i) != 0 ? HIGH : LOW);
delayMicroseconds(10);
digitalWrite (SCLK, HIGH);
delayMicroseconds(10);
}
delayMicroseconds(100);
}
//-------------------------------------------------------
void DriverInit()
{
pinMode(SCLK, OUTPUT);
pinMode(SDIO, OUTPUT);
digitalWrite(SCLK, HIGH);
delayMicroseconds(5);
digitalWrite(SCLK, LOW);
delayMicroseconds(1);
digitalWrite(SCLK, HIGH);
delay(1025);
DriverWrite(0x00, 0x01);
delay(3000);
}
//-------------------------------------------------------
int DriverReadFrame(byte *arr, int len)
{
byte *pos=arr;
byte *uBound=arr+len;
unsigned long timeout = millis() + 1000;
byte val;
DriverWrite(0x08, 0x2A);
while( millis() < timeout && pos < uBound)
{
val = DriverRead(0x08);
//Only bother with the next bit if the pixel data is valid.
if( !(val & 64) )
{
continue;
}
//If we encounter a start-of-field indicator, and the cursor isn't at the first pixel,
//then stop. ('Cause the last pixel was the end of the frame.)
if( ( val & 128 ) && ( pos != arr) )
{
break;
}
*pos = val & 63;
pos++;
}
return (pos-arr);
}
//-------------------------------------------------------
void setup()
{
Serial.begin(57600);
DriverInit();
}
//-------------------------------------------------------
void loop()
{/*
byte x = DriverRead(0x02);
byte y = DriverRead(0x03);
if(x || y)
{
Serial.print("X:");
Serial.print(x,DEC);
Serial.print(" Y:");
Serial.println(y,DEC);
}*/
if (Serial.available() > 0)
{
byte c = Serial.read();
if (c == 'F')
{
byte tmp[324];
int len = DriverReadFrame(tmp,324);
int kk=0;
for(int i=0;i<324;i++)
{
Serial.print(tmp[i]);Serial.print(" ");
kk++;
if (kk==18){Serial.println();kk=0;}
}
Serial.println();Serial.println();
Serial.println(len);
}
}
}
"Мы не в Англии случиться может всякое" Сказано главой МИ6 в Эдинбурге Шотландия.