AVR128DA64 HOW TO SEND SERIAL DATA BY DIGITAL PIN TO CD4094 AND CLOCK OUTPUT TO DIGITAL PIN TO CD4094

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am interfacing AVR128DA64 with cd4094 ic to control the LED indication. For that from one pin I want to send the serial data and from another digital pin i want to send the clock to cd4094. How to do it ? please reply.

Madhusudan Jadhav

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You've asked such a basic question that you need to tell us more about your AVR knowledge level (E.g. Do you know how to do GPIO output).

Or are you actually asking about hardware wiring and what to do with the 4 pins ?

 

Here's a good tutorial:

http://www.friendlywire.com/tutorials/shift/  (unfortunately the implementation detail is PIC16, but that doesn't really affect the good explanation)

 

If you need to; you can always ask here about AVR implementation once you understand more about the chip's interface.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to ask actually define port pin as a name and then use it.

Madhusudan Jadhav

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the Tutorial I linked you may have read:

// define locations of CD4094 controls
#define STROBE RB0
#define DATA RB1
#define CLOCK RB2
#define ENABLE RB3

 

Unfortunately; avr-gcc doesn't allow "nice" GPIO definitions like the PIC compiler does.

 

In the AVR world; there are so many variations on this theme, that there is no one true answer.

 

If I were writing a general AVR driver for CD4094 (non-Arduino); I would write MACROS for the pin functions thus:

 

#define CD4094_STROBE_HI() PORTB |=  (1 << 0)
#define CD4094_STROBE_LO() PORTB &= ~(1 << 0)

#define CD4094_DATA_HI() PORTB |=  (1 << 1)
#define CD4094_DATA_LO() PORTB &= ~(1 << 1)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

project@embedchip.com wrote:
I want to ask actually define port pin as a name and then use it.

For an AVR, that needs to include both which port the pin is in, and which pin number within the port it is.

 

For the newer AVRs, thes ports are usually modelled as a C struct:

Data Direction (PORTx.DIR)

Data Output Value (PORTx.OUT)

Data Input value (PORTx.IN):

 

 

In older AVRs, it was traditional to just define the registers separately; PORTA, DDRA, etc

 

See this recent thread on the different styles:

 

https://www.avrfreaks.net/forum/...

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Mon. Oct 11, 2021 - 08:40 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The CD4094 serial in parallel out shift register, is similar to the common 74ls595, so you should be able to find code you can adapt to this newer AVR.

Here is one shift out function I have for the 595, hope it helps.

void shiftOut(uint8_t bitOrder, uint8_t val)
{
        uint8_t i;
        uint8_t bit;

        for (i = 0; i < 8; i++)  {
        	if (bitOrder == LSBFIRST) {
        		//digitalWrite(dataPin, !!(val & (1 << i)));
        		bit = i;
        	} else {
        		//digitalWrite(dataPin, !!(val & (1 << (7 - i))));
        		bit = 7 - i;
        	}

        	if (val & (1 << bit)) {
        		PORTB |= (1 << PIN_DATA); // HIGH
        	} else {
        	    PORTB &= ~(1 << PIN_DATA); // LOW
        	}

			//digitalWrite(clockPin, HIGH);
        	PORTB |= (1 << PIN_CLOCK); // HIGH

			//digitalWrite(clockPin, LOW);
        	PORTB &= ~(1 << PIN_CLOCK); // LOW
        }
}

Jim

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

Lets go Brandon!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for the solution.

Madhusudan Jadhav