Tags:
create new tag
, view all tags
SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_ORDER_MSB_FIRST | SPI_SCK_LEAD_RISING |SPI_SAMPLE_LEADING | SPI_MODE_MASTER);

The SPI_Init function initialises parameters specific to the SPI required to send information and commands to the transceiver module. The speed is set to 4MHz (the CPU speed divided by 2). The order of information is the MSB first which is standard for SPI. The SPI clock leads on the rising edge, and the data is sampled on the leading edge of the clock. The microcontroller is the SPI master and is initialised as such.

DDRB |= 0xF1; //Enable SS as an output
PORTB |= 0x80; //Pull SS high

Sets the SPI chip select pin as an output and initialises it high as chip select is active low. This will be used when conducting SPI reads and writes.

DRE = 0x00;
ORTE = 0x40; //Enable pull-up on PE6 to be used for interrupt

Sets PE6 as an input and pulls it up. This pin is connected to the interrupt pin on the transceiver module and will be used to notify the microcontroller of certain events.

DDRC = 0x77; //RGB LED output pins LED1(PC4-R, PC5-G, PC6-B) LED2(PC0 - B) Used for USB Status
PORTC = 0x71; //Output High
DDRE |= 0x03; //RGB LED output pins LED2(PE0 - R, PE1 - G)
PORTE |= 0x03; //Output high

Sets Port C and E (not include PE6) as outputs and pulls them up. These pins are used for the RGB LEDs on the board and are active low. These LEDs have no dedicated purpose and have been used to indicate the USB connection status as well as when an unrecognised interrupt has occurred.

DDRA = 0x00; //Port A used for input PORTA = 0x40;

Sets Port A to be used as inputs and pulls PA6 up. Although this port can be used as an input or output, in this case it’s set up as in input to allow the user to read the temperature when the pulled up pin is connected to ground[4].

-- XiaohongWu - 2012-01-31

Topic revision: r1 - 2012-01-31 - XiaohongWu
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback