hey!
i using leonardo control dac via spi. code far looks like
(...)
void setup() {
serial.begin(9600);
// start spi library:
spi.begin();
// initalize the data ready , chip select pins:
// pinmode(datareadypin, input);
pinmode(chipselectpin, output);
// create ground
pinmode(ground, output);
digitalwrite(ground, low);
pinmode(led, output);
digitalwrite(led, low);
cmd_prefix_a = 3 << (4+8); /// creates 0011 0000 0000 0000
cmd_prefix_b = 11 << (4+8); // create 1011 0000 0000 0000
delay(5000);
senddaccmd(true, 2048); /// calls spi.transfer16 , sets slaveselect
}
void loop() {
digitalwrite(led, high);
//select high resolution mode
senddaccmd(false, 3000);
// senddaccmd(true, 4095);
delay(100);
}
in later version, loop wait commands via serial , calls spi-interface. however, want write values dac during startup. however, "senddaccmd(true, 2048)" @ end of setup not transmitted (while call in loop works wanted).
is there reason spi not work during setup?
i of course have "first_loop"-boolean , add like
void loop(){
if (first_loop){
first_loop = false;
senddaccmd(true, 2048);
}
(...)
}
but that's waste of time first runs , therefore ugly.
i using leonardo control dac via spi. code far looks like
(...)
void setup() {
serial.begin(9600);
// start spi library:
spi.begin();
// initalize the data ready , chip select pins:
// pinmode(datareadypin, input);
pinmode(chipselectpin, output);
// create ground
pinmode(ground, output);
digitalwrite(ground, low);
pinmode(led, output);
digitalwrite(led, low);
cmd_prefix_a = 3 << (4+8); /// creates 0011 0000 0000 0000
cmd_prefix_b = 11 << (4+8); // create 1011 0000 0000 0000
delay(5000);
senddaccmd(true, 2048); /// calls spi.transfer16 , sets slaveselect
}
void loop() {
digitalwrite(led, high);
//select high resolution mode
senddaccmd(false, 3000);
// senddaccmd(true, 4095);
delay(100);
}
in later version, loop wait commands via serial , calls spi-interface. however, want write values dac during startup. however, "senddaccmd(true, 2048)" @ end of setup not transmitted (while call in loop works wanted).
is there reason spi not work during setup?
i of course have "first_loop"-boolean , add like
void loop(){
if (first_loop){
first_loop = false;
senddaccmd(true, 2048);
}
(...)
}
but that's waste of time first runs , therefore ugly.
quote
however, "senddaccmd(true, 2048)" @ end of setup not transmitted (while call in loop works wanted).i'm willing bet snippets @ http://snippets-r-us.com.
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Using SPI connection in setup()
arduino
Comments
Post a Comment