CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Optical Mouse Chip

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dsaari



Joined: 05 May 2006
Posts: 25

View user's profile Send private message AIM Address

Optical Mouse Chip
PostPosted: Sat Apr 11, 2009 10:29 am     Reply with quote

I'm trying interface a PIC16F876 @20MHz to a ADSN-2610 optical mouse sensor. I just want to spit out the positional information to my debug screen for now. The question I have is setting up for the SPI communication on this sensor. It uses half duplex so SDI and SDO are coming from the same pin on the sensor. I think I would just need to tie the SDI & SDO together on the pic, but I'm not certain.

The data sheet for the ADSN-26XX is here:
http://www.avagotech.com/docs/AV02-1184EN

Additionally, I am trying to figure out how to configure the SPI port to talk to this thing software wise. I am just finishing up the hardware interface now. I think I have it working because the LED turns on brighter when I bump the board, so I know it's doing it's thing, now I've just got to talk to it.

Any help would be appreciated.

Thanks!
dsaari



Joined: 05 May 2006
Posts: 25

View user's profile Send private message AIM Address

Optical Mouse Sensor
PostPosted: Sat Apr 11, 2009 5:21 pm     Reply with quote

Ok,
I think I've got thinks talking a bit. I can send configuration data to the chip to take it out of power savings mode. I know this is working because the LED goes from dim to bright when I send the configuration data. I went and connected the SDI and SDO pins together. I still can't read any data though. The code below will make the LED shine bright (take it out of power saving mode) but I'm not getting anything on the read.
Code:
#include <16F876.h>        //PIC microcontroller driver
#DEVICE  CCSICD=TRUE        //Use the ICD debugger
#fuses   NOWDT, HS, NOPUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT//, DEBUG
#use     delay(clock=20000000) //20MHz clock
#use     rs232(debugger)
//****************************************************************************//

#define BUTTON  PIN_A5   // Chip button pin
#define LED     PIN_A0   // Chip LED pin
#define CONFIG  0x80
#define STATUS  0x01
#define DELTAY  0x02
#define DELTAX  0x03
#define SQUAL   0x04
#define INIT    0x01
int8 FRANK = 0;
//****************************************************************************//
//**********************************MAIN**************************************//
void main()
{
   setup_adc_ports(NO_ANALOGS);  //Make these I/O pins A/D inputs
   setup_adc(ADC_OFF); //MAke the A/D clock an internal reference
   setup_spi(SPI_MASTER | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16); //setup SPI mode
   setup_timer_1(T1_DISABLED);    //Disable timer1
   setup_timer_2(T2_DISABLED,0,1);//Disable timer2
   printf("\n\r");                //Print out the following to the USART
   printf("\n\r");
   printf("MARVEL MOUSE\n\r");
   printf("***********************************\n\r");
   delay_ms(200);
   spi_write(CONFIG);   
   spi_write(INIT);
   while (TRUE)                        //Main loop
   {
      if (!input(BUTTON))
      {
         output_high(LED);
      }
      else output_low(LED);
      delay_ms(20);
      spi_write(DELTAX);
      delay_ms(10);
      FRANK = spi_read();
      printf("FRANK = %d\n\r", FRANK);
   }
}


Any thoughts?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 11, 2009 6:56 pm     Reply with quote

spi_read() must have a parameter if want to get a clock signal out of
the SCLK pin. This is in the manual. Normally it's done with a 0
parameter. Example:
Code:
result = spi_read(0);
dsaari



Joined: 05 May 2006
Posts: 25

View user's profile Send private message AIM Address

Optical Mouse Sensor
PostPosted: Sat Apr 11, 2009 11:12 pm     Reply with quote

Alright, I tried your recommendation but am still having troubles. I know that I am able to write to the sensor because I can get it to react as I'd expect using power down and reset configurations. I really do feel that it is responding correctly to spi_writes. When I go to read however, I don't get anything back. If I leave the read_spi() blank, FRANK printf's "3". If I put read_spi(0) then FRANK printf's "0". So your recommendation had an effect but It's still not changing when I move the sensor. Any further thoughts or hints?

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 11, 2009 11:36 pm     Reply with quote

My advice is to start with the CCS ds1302 driver and use it as a base
to build your Optical mouse chip driver. The DS1302 is a 3-wire chip.
The CCS driver uses software SPI to talk to the chip. I think you can
modify the DS1302 driver fairly quickly to work with the Avago chip.
Quote:
c:\program files\picc\drivers\ds1302.c
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: Optical Mouse Sensor
PostPosted: Sun Apr 12, 2009 4:47 am     Reply with quote

dsaari wrote:
Alright, I tried your recommendation but am still having troubles. I know that I am able to write to the sensor because I can get it to react as I'd expect using power down and reset configurations. I really do feel that it is responding correctly to spi_writes. When I go to read however, I don't get anything back. If I leave the read_spi() blank, FRANK printf's "3". If I put read_spi(0) then FRANK printf's "0". So your recommendation had an effect but It's still not changing when I move the sensor. Any further thoughts or hints?

Thank you.


This is because the SPI and SPO are tied together. Whatever is written on SPO will appear on SPI. The solution is to put a 1K series resistor in the SDO output from the PIC.

So the schematic has the PIC SPI connected directly to the sensor and the PIC SDO is connected via the series resistor to SPI.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
dsaari



Joined: 05 May 2006
Posts: 25

View user's profile Send private message AIM Address

Optical Mouse Sensor
PostPosted: Sun Apr 12, 2009 6:23 am     Reply with quote

Thank you asmallri! I added the 1kohm and now I got data. I don't know what it means yet but I've got it. When I move, the numbers seem to increase and decrease depending on direction. I get zeros if I stop, but I think the register clears itself when I read it. Again thank you!
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Sun Apr 12, 2009 1:27 pm     Reply with quote

Hi Dsaari,

I suppose that what you read is the difference of position since the last reading.
It would explain why you've got 0 when you don't move.
To know the position at each time, you have to add the value of each of readings.

Good luck,
Franck.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group