Go Down

Topic: Arduino Uno and CD4094 [Solved] (Read 1 time) previous topic - next topic

cinnamonBunny

Jan 15, 2017, 01:51 pm Last Edit: Jan 16, 2017, 06:42 pm by cinnamonBunny
I´m having trouble with Arduino Uno and a 16-bit shift register made out of two CD4094´s.
The program appears to be working, but the leds connected on the outputs of the shift registers do nothing. What am I doing wrong ?

Code: [Select]


#include <avr/pgmspace.h> 
#include <SPI.h>

const int latchPin = 10;  //Pin connected to STR(pin 1) of HEF4094
//clock = 13, mosi = 11
const int eprom[12] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800};

int address = 0;
byte i = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(latchPin, OUTPUT);
  digitalWrite(latchPin, LOW);
  SPI.beginTransaction(SPISettings(500000, LSBFIRST, SPI_MODE0)); // initialize SPI
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  address = eprom[i];
  Serial.print(i);
  Serial.print(" ");
  Serial.println(address, HEX);
  Serial.println(" ");
  addressOut(address % 256, address / 256);
  delay(1000);
  i++;
  if(i > 11) i = 0;
}

void addressOut(byte addressLow, byte addressHigh)
{
  digitalWrite(latchPin, HIGH);
  SPI.transfer(addressLow);
  SPI.transfer(addressHigh);
  //delay(1);
  digitalWrite(latchPin, LOW);
}


PaulS

Did you try the code with just one shift register, first? Do you KNOW that the LEDs are connected correctly?

The art of getting good answers lies in asking good questions.

cinnamonBunny

#2
Jan 16, 2017, 06:49 pm Last Edit: Jan 16, 2017, 06:56 pm by cinnamonBunny
Hi

I got it working by replacing

Code: [Select]


SPI.beginTransaction(SPISettings(500000, LSBFIRST, SPI_MODE0));



with

Code: [Select]


SPI.begin();
SPI.setBitOrder(LSBFIRST);




And apparently Arduino needs to be connected to USB for the program to work at all (?)
(It would be interesting to know tough  why the version above didn´t work.)

Gustavo_Murta

#3
Aug 26, 2019, 04:06 pm Last Edit: Aug 26, 2019, 04:07 pm by Gustavo_Murta
Hi,
Run perfectly with two HEF4094.
Thank You.

Code: [Select]
#include <SPI.h>

const int latchPin = 10;  // Pin connected to STR(pin 1) of HEF4094
//clock = 13, mosi = 11
const int eprom[12] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800};

int address = 0;
byte i = 0;

void setup()
{
  pinMode(latchPin, OUTPUT);
  digitalWrite(latchPin, LOW);
  SPI.beginTransaction(SPISettings(500000, LSBFIRST, SPI_MODE0));             // initialize SPI 
  SPI.begin();
  Serial.begin(9600);
}

void addressOut(byte addressLow, byte addressHigh)
{
  digitalWrite(latchPin, HIGH);
  SPI.transfer(addressLow);
  SPI.transfer(addressHigh);
  delay(1);
  digitalWrite(latchPin, LOW);
}

void loop()
{
  address = eprom[i];
  Serial.print(i);
  Serial.print(" ");
  Serial.println(address, HEX);
  Serial.println(" ");
  addressOut(address % 256, address / 256);
  delay(500);
  i++;
  if (i > 11) i = 0;
}

Gustavo_Murta

#4
Aug 26, 2019, 04:46 pm Last Edit: Aug 26, 2019, 04:55 pm by Gustavo_Murta
Running in FAST mode, use SPIMODE1.
Best without spurious pulses.

Code: [Select]
#include <SPI.h>

//clock = D13, mosi = D11
const int latchPin = 10;  // Pin connected to STR(pin 1) of HEF4094
const int eprom[12] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800};

int address = 0;
byte i = 0;

void setup()
{
  pinMode(latchPin, OUTPUT);
  digitalWrite(latchPin, LOW);
  SPI.beginTransaction(SPISettings(500000, LSBFIRST, SPI_MODE1));       //  initialize SPI  500KHz
  SPI.begin();   
}

void addressOut(byte addressLow, byte addressHigh)
{
  SPI.transfer(addressLow);
  SPI.transfer(addressHigh);
  digitalWrite(latchPin, HIGH);
  digitalWrite(latchPin, LOW);
}

void loop()
{
  address = eprom[i]; 
  addressOut(address % 256, address / 256);
  i++;
  if (i > 11) i = 0;
}

Go Up