Shift out using SPI doesn't work.
actually, questioned on arduino stackexchange,
but got nothing i'm asking again ;-(
i made sample using 2 74hc595 on arduino uno.
so did this:

(there isn't resistor on image, there 220ohm resistor on every leds.)
and uploaded code.
and worked expected. but, when changed sketch this,
74hc595s aren't working. leds aren't on.
printing serial works well. 74hc595s aren't working.
and removing serial-related thing doesn't solved problem.
where did wrong?
but got nothing i'm asking again ;-(
i made sample using 2 74hc595 on arduino uno.
so did this:

(there isn't resistor on image, there 220ohm resistor on every leds.)
and uploaded code.
code: [select]
//1.6us+62.5ns
#include <spi.h>
#define sbi(port, bit) (port) |= (1 << (bit))
#define cbi(port, bit) (port) &= ~(1 << (bit))
int latchpin = 12;
int clockpin = 13;
int datapin = 11;
byte data[]={ 0b10101010,0b11001100 };
void _595_out() {
cbi(portb, 4);
spi.transfer(data[0] );
spi.transfer( data[1] );
sbi(portb, 4);
}
void setup() {
pinmode(latchpin, output);
pinmode(clockpin, output);
pinmode(datapin, output);
spi.setclockdivider(spi_clock_div2);
spi.setbitorder(msbfirst);
spi.setdatamode(spi_mode0);
spi.begin();
}
void loop() {
_595_out();
}
and worked expected. but, when changed sketch this,
code: [select]
//1.6us+62.5ns
#include <spi.h>
#define sbi(port, bit) (port) |= (1 << (bit))
#define cbi(port, bit) (port) &= ~(1 << (bit))
#define chipno 2
int latchpin = 12;
int clockpin = 13;
int datapin = 11;
byte data[]={ 0b10101010,0b11001100 };
void _595_out() {
cbi(portb, 4);
spi.transfer(data[0]);
spi.transfer(data[1]);
sbi(portb, 4);
}
void setup() {
pinmode(latchpin, output);
pinmode(clockpin, output);
pinmode(datapin, output);
spi.setclockdivider(spi_clock_div2);
spi.setbitorder(msbfirst);
spi.setdatamode(spi_mode0);
spi.begin();
serial.begin(9600);
}
void loop() {
for(unsigned int z = 0; z < 65535; z++) {
data[0] = z & 255;
data[1] = (z & 65280) >> 8;
serial.println("a");
serial.print(data[0]);
serial.print("/");
serial.println(data[1]);
serial.println("b");
_595_out();
serial.println("c");
delay(500);
}
}
74hc595s aren't working. leds aren't on.
printing serial works well. 74hc595s aren't working.
and removing serial-related thing doesn't solved problem.
where did wrong?
and uploaded code.you can't use miso pin slaveselect (latch) pin. try using pin 10 default slaveselect spi.code: [select]int latchpin = 12;
int clockpin = 13;
int datapin = 11;
where did wrong?
Arduino Forum > Using Arduino > Programming Questions > Shift out using SPI doesn't work.
arduino
Comments
Post a Comment