help with code snipit.

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

help with code snipit.

Post by ulao » Sun Jun 28, 2009 4:23 am

Hey all, I want to adapt the ps2 example code in to my project. There are few lines I just dont understand. I'm sure its some sort of interrupt code but I need to change the pins and dont understand it.

is SPCR tied to port b, and I need port c's register, as far as I can tell from the data sheet its just a Control Register?

This code uses port B, I need it to use port C, and also changes the pin assignments.
Here is what I get from the SPCR setting.

[int not enable the ], [enable SPI ], [ Master SPI mode ( in bit 5 instead of 4?) ],[ bit 4 gets SPR1 that should be in bit 1],[ bit 3 gets SPR1 that should be in bit 0],[bit 2 gets DORD instead of CPHA],[bit 2 gets CPHA instead of SPR1],[bit 2 gets CPOL instead of SPR0]. Are these not order depended or something ?

Code: Select all

void spi_mInit()
{
   // SPI, master, clock/128 = 93.75khz (187.5 didn't work...)
   SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0)|(1<<DORD)|(1<<CPHA)|(1<<CPOL);
}
unsigned char spi_mSend(unsigned char podatek)   //straight from documentation
{

   // Gets information, sends it, waits untill it's sent, then reads the same register (used for both Input and Output) and returns it

   /* Start transmission */
   SPDR = podatek;
   while(!(SPSR & (1<<SPIF)));

   return SPDR;
}

Later on it does a ps2buffer[0]=spi_mSend(0x01); but how does it know what pin to look at?

Post Reply