数据表:(Atmega 324A)http://www.atmel.com/images/Atmel-8272-8-bit-AVR-microcontroller-ATmega164A_PA-324A_PA-644A_PA-1284_P_datasheet.pdf
数据表:(DAC) http://www.ti.com/lit/ds/symlink/dac101s101.pdf
你好呀!!
我正在学习c中的嵌入式编程,所以请多多包涵。
我正在尝试使用通过 SPI 连接到 ATmega324A 的 DAC (DAC101S101) 生成波。Dac 是单向的。现在我只是想从 dac 获得输出。我制作了一个 lut,我将使用它来获得所需的正弦波。另外,如何调制波的频率?(比如让我们说 4000Hz)(另外我已经将外部振荡器连接到 ATmega 芯片。)
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);
}
}
谢谢!!!!