mohammad3d
Joined: 28 Mar 2009 Posts: 17
|
Avago ADNS 7550 Laser mouse sensor driver |
Posted: Tue Oct 16, 2018 6:42 am |
|
|
Hi everyone,
I try to read an Avago ADNS-7550 laser mouse sensor with dsPic micro and
finally Do this...
I share my experience with all of you and I hope this useful for your projects.
Regards,
Mohammad Kouchekzadeh.
Source :
Code: |
// This program drive and read Data from Avago ADNS-7550 laser mouse sensor
// via 4 wire SPI protocol
// PIC is master device and Avago ADNS-7550 is slave device
// You can find more detail in avago AV02-0685EN.pdf file
// program by Mohammad Kouchekzadeh
// E-mail [email protected]
#include <30F6014A.h>
#fuses XT,NOWDT
#use delay(clock=10000000)
#use rs232(baud=38400,UART2,parity=N,bits=8,TIMEOUT=20)
#use standard_io(F)
#use standard_io(G)
#define Clock_pin PIN_F6 //-->connect to ADNS-7550 pin 5
#define Data_in_pin PIN_F7 //-->connect to ADNS-7550 pin 4
#define Data_out_pin PIN_F8 //-->connect to ADNS-7550 pin 6
#define NCS PIN_G3 //-->connect to ADNS-7550 pin 3 Chipselect active low
/*
////////// read data from Master device /////////////////////
unsigned int8 read_data_slave_mode(void)
{
unsigned int8 DATA;
signed int8 i = 8;
while(input(PIN_G2)==1);
for(i=7;i!=-1;i--) {
while(input(Clock_pin)==1);//wait for falling edge
while(input(Clock_pin)==0);//wait for rising edge
if(input( Data_in_pin))
bit_set(DATA,i);
else
bit_clear(DATA,i);
}
return(DATA);
}
*/
void writeRegister(unsigned int8 DATA)
{
int1 SPI_DATA=0;
signed int8 clock_pulse=0;
delay_us(300);
for(clock_pulse=7;clock_pulse!=-1;clock_pulse--)
{
output_bit(Clock_pin,0);
delay_us(70);
SPI_DATA=DATA>>clock_pulse;
output_bit(Data_out_pin,SPI_DATA);
delay_us(30);
output_bit(Clock_pin,1);
delay_us(100);
}
output_bit(Data_out_pin,1);
}
unsigned int8 readRegister(void)
{
unsigned int8 DATA;
signed int8 i = 8;
delay_us(300);
for(i=7;i!=-1;i--) {
output_bit(Clock_pin,0);
delay_us(100);
output_bit(Clock_pin,1);
delay_us(30);
if(input(Data_in_pin))
bit_set(DATA,i);
else
bit_clear(DATA,i);
delay_us(70);
}
output_bit(Clock_pin,1);
return(DATA);
}
void main()
{
int8 i=0,j=1;
unsigned int8 data[50];
delay_ms(500);
/////////// Start ADNS-7550 power up sequence /////////////////
///// Drive NCS high, then low to reset the SPI port //////////
output_bit(NCS,1);
delay_ms(1);
output_bit(NCS,0);
delay_ms(1);
output_bit(NCS,1);
delay_ms(1);
output_bit(NCS,0);
//Note:in write operation The first byte contains the address (seven bits) and
// has a “1” as its MSB to indicate data direction : 0x3A->0xBA
//Note:in read operation address MSB bit is '0': 0x3A->0x3A
//Write 0x5a to register 0x3a
writeRegister(0xBA);
writeRegister(0x5A);
//Wait for at least one frame
delay_us(1350);//wait
//Clear observation register
writeRegister(0xAE);
writeRegister (0x00);
//Wait for at least one frame
delay_us(1350);
//Wait at least one frame and check observation
//register, all bits 0-3 must be set.
writeRegister(0x2E);
data[i++]=readRegister();
//Read from registers 0x02, 0x03, 0x04 and 0x05 (or
//read these same 4 bytes from burst motion register
//0x42) one time regardless of the motion pin state
writeRegister(0x02);
data[i++]=readRegister();
writeRegister(0x03);
data[i++]=readRegister();
writeRegister(0x04);
data[i++]=readRegister();
writeRegister(0x05);
data[i++]=readRegister();
//Write 0x27 to register 0x3C
writeRegister(0xBC);
writeRegister(0x27);
//Write 0x0a to register 0x22
writeRegister(0xA2);
writeRegister(0x0A);
//Write 0x01 to register 0x21
writeRegister(0xA1);
writeRegister(0x01);
//Write 0x32 to register 0x3C
writeRegister(0xBC);
writeRegister(0x32);
//Write 0x20 to register 0x23
writeRegister(0xA3);
writeRegister(0x20);
//Write 0x05 to register 0x3C
writeRegister(0xBC);
writeRegister(0x05);
//Write 0xB9 to register 0x37
writeRegister(0xB7);
writeRegister(0xB9);
//write dummy data
writeRegister(0x00);
writeRegister(0xFF);
//Set LASER_CTRL0 register
writeRegister(0x9A);
writeRegister(0xC0);
//Set LASER_CTRL1 register
writeRegister(0x9F);
writeRegister(0x00);
//Set LSRPWR_CFG0 register
writeRegister(0x9C);
writeRegister(0xDD);
//Set LSRPWR_CFG1 register
writeRegister(0x9D);
writeRegister(0x22);
//write dummy data
writeRegister(0x00);
writeRegister(0xFF);
//Set Configuration2_Bits register
writeRegister(0x92);
writeRegister(0x06);
//Read Inverse_Revision_ID register(Must be 0xfc)
writeRegister(0x3E);
data[i++]=readRegister();
//Read Inverse_Product_ID register(Must be 0xcd)
writeRegister(0x3F);
data[i++]=readRegister();
output_bit(NCS,1);
/*
for(j=0;j<i;j++)
{
putc(data[j]);
}
*/
for(;;)
{
output_bit(NCS,0);
//// Read Delta_X_L register
writeRegister(0x03);
data[0]=readRegister();
//// Read Delta_Y_L register
writeRegister(0x04);
data[1]=readRegister();
output_bit(NCS,1);
delay_ms(20);
if(data[0]!=0)
putc(data[0]);
//putc(data[1]);
}
}
|
|
|