I'm having some difficulty setting up SPI to receive data from the the PmodALS. I'm using the 328PB board with the initialization and receive code below:
void SPI_MasterInit(void)
{
DDRC |= (1<<PORTC1); //set SCK (PC1) to output.
DDRC &= ~(1<<PORTC0); //Set MISO (PC0) as input.
DDRE |= (1<<PORTE3) | (1<<PORTE2); // Set MOSI (PE3) to output and SS (PE2) to output
// Enable SPI, Master
SPCR1 |= (1<<SPE1) | (1<<MSTR1) | (1<<SPR10); //Set to /16 prescaler so peripheral PmodALS operates at 1MHZ
}
// Sends a 16bit word (command + data) to DAC over SPI
int SPI_receiver_for_ALS(void)
{
PORTE &= ~(1<<PORTE2); // Pull Slave_Select (PORTE2) low to tell it to start reporting
data = (SPDR1 << 8); //Take first 8 bits of information
while(!(SPSR1 & (1<<SPIF1))); // Wait for transmission complete
data |= (SPDR1 >> 8); //Take last 8 bits of information
while(!(SPSR1 & (1<<SPIF1))); // Wait for transmission complete
PORTE |= (1<<PORTE2); // Pull Slave_Select (PORTE2) high to tell it to stop reporting
return data;
}
The program gets stuck in the wait for transfer loop, and outputs no data values. When I disable it, I receive values of zero.
I've scoured the datasheets and I'm not sure what I missed. Does anybody have an insights to what I need to do? (I attached the rest of my code as reference)
Question
Brandon Dinsmore
I'm having some difficulty setting up SPI to receive data from the the PmodALS. I'm using the 328PB board with the initialization and receive code below:
void SPI_MasterInit(void)
{
DDRC |= (1<<PORTC1); //set SCK (PC1) to output.
DDRC &= ~(1<<PORTC0); //Set MISO (PC0) as input.
DDRE |= (1<<PORTE3) | (1<<PORTE2); // Set MOSI (PE3) to output and SS (PE2) to output
// Enable SPI, Master
SPCR1 |= (1<<SPE1) | (1<<MSTR1) | (1<<SPR10); //Set to /16 prescaler so peripheral PmodALS operates at 1MHZ
}
// Sends a 16bit word (command + data) to DAC over SPI
int SPI_receiver_for_ALS(void)
{
PORTE &= ~(1<<PORTE2); // Pull Slave_Select (PORTE2) low to tell it to start reporting
data = (SPDR1 << 8); //Take first 8 bits of information
while(!(SPSR1 & (1<<SPIF1))); // Wait for transmission complete
data |= (SPDR1 >> 8); //Take last 8 bits of information
while(!(SPSR1 & (1<<SPIF1))); // Wait for transmission complete
PORTE |= (1<<PORTE2); // Pull Slave_Select (PORTE2) high to tell it to stop reporting
return data;
}
The program gets stuck in the wait for transfer loop, and outputs no data values. When I disable it, I receive values of zero.
I've scoured the datasheets and I'm not sure what I missed. Does anybody have an insights to what I need to do? (I attached the rest of my code as reference)
Thanks a lot!
main.c uart.c uart.h
PmodALS datasheet.pdf
Link to comment
Share on other sites
0 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.