我想传输数据 A1A2A3A4。从 ATxmega128A1 的内部存储器通过 SPI 主机到从机形成两个单独的 DAC 转换器,这样 DAC1 应该有 A1A3 和 DAC2 和 A2A4。
如何在 AVR 中编写代码
// Transfer data from internal memory via SPI from Master to single Slave
if ( (SWITCHPORTL.IN & PIN2_bm) == 0 )
{
flip = false;
j = 0;
{
// Switch on LED 2
LEDPORT.OUTSET = PIN2_bm;
// Switch on LED 3
LEDPORT.OUTSET = PIN3_bm;
}
while (j < NUM_BYTES)
{
if (flip == false)
{
// Set slave select line low (active) for Port C
PORTC.OUTCLR = PIN4_bm;
}
// Give the data to the data register of the Master
SPIC.DATA = __far_mem_read(j+SDRAM_ADDR);
if (flip == true)
{
_delay_us(0.7); // wait for the 2nd 8-bit-block to be send -> delay 0.7us
// Set slave select line high (inactive)
PORTC.OUTSET = PIN4_bm;
_delay_us(1.9); // delay to adjust to sampling frequency 100 kHz -> 6.9us 200kHz -> 1.9us
}
flip = !flip;
j++;
}
}