DataSheet:(Atmega 324A) http://www.atmel.com/images/Atmel-8272-8-bit-AVR-microcontroller-ATmega164A_PA-324A_PA-644A_PA-1284_P_datasheet.pdf
DataSheet:(DAC) http://www.ti.com/lit/ds/symlink/dac101s101.pdf
Hi there!!
i'm learning Embedded programming in c, so please bear with me.
I am trying to generate a wave using a DAC (DAC101S101) which is connected to ATmega324A via SPI. The Dac is uni-Directional. right now i'am just trying to get a output off the dac. I have made a lut which i will use to get the required sine wave. Also, how do I modulate the frequency of the wave ? (like lets say 4000Hz)(Also I have connected a external oscillator to the ATmega chip.)
i Have connected:
PB5 -- MOSI -------> DIN (DAC)
PB7 -- SCK -------> SCK (DAC)
PA1 --------------->#Sync(DAC)
void init_SPI_Master(void) {
/*
* Set MOSI and SCK output, all others input
* DDR_SPI = (1<<DD_MOSI)| (1<<DD_SCK);
*
* (for ATmega 324A
*
* DDRB = (1<<DDB5) | (1<<DDB7)
*
*/
DDRB = (1<<5) | (1<<7);
/*
*Enable SPI, Master, set clock rate fck/16;
*
*/
SPCR0 = (1<<SPE0) | (1<< MSTR0) | (1<<SPR00) | (1<<CPOL0);
}
void Tx_SPI_Master (unsigned char data) {
/*
* Start transmition
*
*/
SPDR0 = data;
/*
* is Tx complete ?
*
*/
}
int main(void)
{
unsigned char data1 = 0x04;
unsigned char data2 = 0xFC;
DDRA = 1 << 1;
PORTA = 1 << 1;
init_SPI_Master();
while(1)
{
//TODO:: Please write your application code
//sync: i'm not sure as how to provide sync to the dac
// according to the datasheet as soon as the sync bit goes low the
// register starts accepting data into Din.
// so right now i am trying to input 0000001111111100 into
// the dac.
PORTA = 1 << PINA1;
PORTA = 0 << PINA1;
Tx_SPI_Master(data1);
Tx_SPI_Master(data2);
}
}
Thank you!!!!