[Icc-avr] USART SPI Master

Andrew andrew_166 at msn.com
Mon Apr 21 03:31:38 PDT 2008


Hi,

I have written the following : -

//-----------------------------------------------------------------------------
//
// Function name : uart2_SPI
//
// Returns : None 
//
// Parameters : None 
//
// Purpose : UART2 initialize as an SPI Master.
//
//-----------------------------------------------------------------------------
void uart2_SPI(void)
{
// Baud rate must be set to 0 prior to enabling the USART as SPI
// master, to ensure proper initialization of the XCK line.
UBRR2 = 0;

// Set XCK line to output, ie. set USART in master mode.
DDRH |= BIT(4); // Set XCK (BIT(4)) as an output

// Set USART to Master SPI mode.
UCSR2C = (1 << UMSEL21) | (1 << UMSEL20);

// Set clock polarity and phase to correct SPI mode.
UCSR2C = (1 << UCPOL2) | (1 << UCPHA2); // 

// Enable RX and TX.
UCSR2B = (1 << RXEN2) | (1 << TXEN2); 

// Set baud rate. Must be set _after_ enabling the transmitter.
UBRR2 = 7; // Gives 1MHz 

}

For some reason i am getting "undeclared identifier `UCPHA2'"  in the ICCAVR compilier i am using an ATmega640 and i have included the correct header s: -

#include <iom640v.h> // Include the ATmega 640 header file 
#include <macros.h> // Include ICCAVR's macro's libary header

Can anybody see what i have done wrong, or is it simply that the ICCAVR header does not contain UCPHA2 and thus i must set the register maually?



Thanks,



Andy  

  ----- Original Message ----- 
  From: Andrew 
  To: Discussion list for ICCAVR and ICCtiny Users. You do NOT needtosubscribeto icc-announce if you are a member of this. 
  Sent: Monday, April 21, 2008 10:33 AM
  Subject: [Icc-avr] USART SPI Master


  Hi, 

  Is there or does anybody have an example (written in c) of setting up and using the USART as an SPI master? 

  Thanks, 

  Andy 


------------------------------------------------------------------------------


  _______________________________________________
  Icc-avr mailing list
  Icc-avr at imagecraft.com
  http://dragonsgate.net/mailman/listinfo/icc-avr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20080421/68cd2728/attachment.html


More information about the Icc-avr mailing list