Problem setting the baud rate [RESOLVED]
hi,
i new arduino, , trying use arduino uno send serial commands--so output only. my problem want use optoisolators, , arduino seems send serial commands @ high speed. i know should change baud rate, strangely, when change in code data written @ same speed. i looking @ output on oscilloscope, , bits written @ same rate no matter set baud rate. my code attached below--i'd appreciate help!
thanks,
andrea
#include "spi.h" // necessary library
int ss=10; // using digital pin 10 spi slave select
void setup()
{
serial.begin(300);
pinmode(13, output);
pinmode(ss, output); // use ss pin
spi.begin(); // wake spi bus.
spi.setbitorder(msbfirst); //correct order ad5764.
spi.setdatamode(spi_mode1); //1 , 3 communicate dac. 1 1 works no clock divider.
}
void setvalue(byte db[3])
{
spi.transfer(db[0]); // send command byte. 00 (write-bar, 0) 010 (data register) 100 (select a-d). decimal: a = 16, b = 17, c = 18, d = 19, = 20.
spi.transfer(db[1]); // significant data bits
spi.transfer(db[2]);//lowest 8 data bits
}
void loop()
{
serial.flush();
byte bytes[3];
bytes[0]=85;
bytes[1]=85;
bytes[2]=85;
setvalue(bytes);
delay(500);
}
i new arduino, , trying use arduino uno send serial commands--so output only. my problem want use optoisolators, , arduino seems send serial commands @ high speed. i know should change baud rate, strangely, when change in code data written @ same speed. i looking @ output on oscilloscope, , bits written @ same rate no matter set baud rate. my code attached below--i'd appreciate help!
thanks,
andrea
#include "spi.h" // necessary library
int ss=10; // using digital pin 10 spi slave select
void setup()
{
serial.begin(300);
pinmode(13, output);
pinmode(ss, output); // use ss pin
spi.begin(); // wake spi bus.
spi.setbitorder(msbfirst); //correct order ad5764.
spi.setdatamode(spi_mode1); //1 , 3 communicate dac. 1 1 works no clock divider.
}
void setvalue(byte db[3])
{
spi.transfer(db[0]); // send command byte. 00 (write-bar, 0) 010 (data register) 100 (select a-d). decimal: a = 16, b = 17, c = 18, d = 19, = 20.
spi.transfer(db[1]); // significant data bits
spi.transfer(db[2]);//lowest 8 data bits
}
void loop()
{
serial.flush();
byte bytes[3];
bytes[0]=85;
bytes[1]=85;
bytes[2]=85;
setvalue(bytes);
delay(500);
}
i think confusing rs-232 serial port spi port. serial.begin(300) sets rs-232 serial port. has nothing speed of spi port. doubt can low 300 baud.
the spi speed set specifying divider this:
[edited]this can go 2 down 128 in powers of 2 - example, spi_clock_div32
iirc default spi_clock_div4
why want slow down spi clock?
pete
the spi speed set specifying divider this:
code: [select]
spi.setclockdivider(spi_clock_div2);
[edited]this can go 2 down 128 in powers of 2 - example, spi_clock_div32
iirc default spi_clock_div4
why want slow down spi clock?
pete
Arduino Forum > Using Arduino > Programming Questions > Problem setting the baud rate [RESOLVED]
arduino
Comments
Post a Comment