ATtiny3217 I2c problem

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

Hi, i have problem with ATtiny3217. I am trying to display something on 7seg display via I2c.

 

My set:

>ATtiny3217

>I2c expander -  PCF8574

 

The problem is following:

>The display is working properly when i multiplex the 7segment display in while loop in my code

>Whenever i enable interrupts whole thing crashes, diode stops blinking and i can’t see any change on the display. Also P/S diode is blinking automatically

>When I disattache +5V cable on my breadboard, the diode starts blinking 

>sometimes when i unplug and plug the +5V to display, it starts working

 

I know for sure that the way i display something on the display is working, but whenever i want to refresh display via interrupts, or when i just simply turn the interrupts on, the display wont work.

 

Also can someone explain to me how to connect pull-up resistors to the expander?

 

ps. I know that digits i am currently displaying don’t make sence, but im just trying to get the display working with dynamicly displayed symbols

 

 

#include <atmel_start.h>
#include <util/delay.h>
#include "include/i2c_simple_master.h"
    uint8_t segmenty[] = {0x00, 0x01, 0x02, 0x04, 0x08, 0x0F};
    //uint8_t pozycje[] = {0x00, 0x10, 0x20, 0x40, 0x80, 0xF0};
    uint8_t pozycje[] = {0x10, 0x20, 0x40, 0x80};
    uint8_t dane[] = {1,0,2,4};

 

ISR(TCA0_OVF_vect)
{
    DIODA_toggle_level(); //LED blink
    
    //static int inc =0;
    //I2C_0_read1ByteRegister(0x20, (pozycje[inc]+segmenty[dane[inc]]));
    //if (inc++==3){
        //inc =0;
    //}
    TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm;
}
 

int main(void)
{
    /* Initializes MCU, drivers and middleware */
    atmel_start_init();

    /* Replace with your application code */
    while (1) {
            static int inc =0;
            I2C_0_read1ByteRegister(0x20, (pozycje[inc]+segmenty[dane[inc]]));
            if (inc++==3){
                inc =0;
            }
    }
}
 

 

 

 

Attachment(s): 

Last Edited: Thu. May 12, 2022 - 05:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the AVR freaks!!

 

You pull up SDA and SCL to the logic supply (your 3.3V or 5V)  use a few K ohms.  Maybe your PCF board already has some?

 

How do you expect to see anything ...you are showing various values, but there are no delays...are you  hoping to see thousands of different values every second???

 

What diode starts blinking?  Why do you say diode--do you mean LED? nobody calls it a diode (though it is light emitting diode).

 

Why do you need interrupts now?  Use them some other time.  What are you making?

 

Keep at it, you are at the beginning.  Write your own code, not using start.  Get Fleury's I2C code--it works

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Thu. May 12, 2022 - 04:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is always wise to post links to your hardware modules.

Most Ebay PCF8574 expander boards have pullups on the pcb.  Post a link to the Ebay sale page and we can see for ourselves.

 

The PCF8574 has only got Qazi outputs.   i.e. you can sink current but not source current.

 

Fine for common anode 7-segment module segments.

But you need PNP transistors for each (common) digit pin.

 

Hey-ho.   Other I2C expander chips possess DDR registers and can do push-pull output.

 

You have 8 segment pins and 4 digit pins.

So you are probably going to use the PCF8574 for the segments.   And the AVR for the digit pins.

Ideally via PNP transistors.   But if you are careful with the current you can possibly use the Tiny3217 pins directly.

 

If you are unsure about electronics it is simple to post links.   Not so simple to explain in words !!

A pencil drawing of your schematic / wiring is fine.

 

David.

Last Edited: Thu. May 12, 2022 - 04:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
Get Fleury's I2C code--it works

Not on the tiny0-1 AVR's, but there is known good code available.

 

 

FF = PI > S.E.T

 

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

The Fleury bit-bang i2cmaster.S works with any AVR.   Obviously with the correct SFR names.

 

First off show your regular Multiplex schematic.

Then the PCF8574 version.

 

The software difference is pretty trivial.   i.e. you just exchange a PORTx.OUT=value statement for an i2c_write(value)

 

But the hardware schematic must be correct.

 

David.

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

Yes i meant LED, sorry i didnt paste all of my code.

I am not using delay on purpose. I need interrupts to refresh display with exact frequency.

I am trying to make 7seg 4 positional display via i2c, because of lack of pins i am trying to display the value on the display dynamically, that's why i need precise frequency. I cant use delay because it was not designed for that kind of work, despite 7seg i want this microcontroller do something more, delay just wont do.

What do you mean write my own code? There is a I2c library ready to use when i create "Atmel Start Project", i dont want to write something that is already written.

Last Edited: Thu. May 12, 2022 - 05:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Expander: https://www.ebay.com/itm/2510471...

Display: http://www.xlitx.com/Products/7-...

 

I cant use 4 pins of microcontroller for choosing digits, i need to get it done only via i2c. I know that this expander has 8 pins and it isnt enough, but in the future i will get one with 16 pins, and for now i need to figure out the way to display something on the display,

so i just plugged first 4 pins of the expander to display anodes for choosing digit, and 4 pins for choosing 4 of 7 segments. And i am trying to display something dynamically.

 

Function: I2C_0_read1ByteRegister(address, value); works and displays everything beautifully how i want, the problem occurs when i try to run it after the interrupt,

segments are pretty dim but if i put the pnp transistors for each digit it should make display shine brighter, am i right?

 

I am really bad with schematics, i will try to draw something. I have attached a photo to my post, it might help you.

 

I thank you very much for your replay and help.

Last Edited: Thu. May 12, 2022 - 06:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I drew the schematics, i know that it is autistic, but thats the way i have connected everything

Attachment(s): 

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

ScoobySnackos wrote:
I drew the schematics, i know that it is autistic

Compared to most shown here, that is one of the neatest drawings I seen!  Nice job.

 

Jim

 

 

FF = PI > S.E.T

 

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

Pencil would have been fine.   You have a very neat drawing.

 

1k0 is a bit strong for I2C pullup.  4k7 - 10k for 5V chip.

220R is a bit weak for segments

Remove the 0R from the unused segments.   i.e. open-circuit. 

 

You have a common-anode display.   P1-P3 cannot source current.   Only enough for a keypad.  So remove the unused segments.   They will only steal the wimpy current.

 

Buy a MCP23017 breakout board.   It is a bit harder to program but can source and sink 25mA.

Or use two PCF8574 with PNP transistors on the digit selects.

 

Otherwise I would start by creating a 5ms Timer interrupt.   Multiplex the Tiny3217 GPIO pins via the ISR().

 

When you are happy with the GPIO multiplexing you replace with I2C code into the ISR().

 

Yes,  it is always wise to use ready-made libraries.

I am not sure whether the Start code would be suitable for multiplexing.

As I said.  Get multiplexing working on 3217 GPIO first.

 

I don't think that I have a raw 4-digit common-anode anywhere.

But I have several on dedicated I2C boards.   e.g. https://www.ebay.co.uk/itm/33341...

And several driven by GPIO (and PNPs)

 

Actually I could simulate multiplexing by writing a single digit at a time to the intelligent I2C driver.

 

David.

 

p.s.   Surely this

            I2C_0_read1ByteRegister(0x20, (pozycje[inc]+segmenty[dane[inc]]));
should be

            I2C_0_write1ByteRegister(0x20, (pozycje[inc]+segmenty[dane[inc]]));
 

Last Edited: Thu. May 12, 2022 - 08:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ScoobySnackos wrote:
There is a I2c library ready to use when i create "Atmel Start Project",
Likewise for MPLAB Code Configurator (MCC) Melody which can be imported into Microchip Studio.

 

I2C Driver Documentation for ATtiny Device Families | MCC Melody API Reference for AVR MCU Families

Table: Peripheral Support by MCU Device | MCC Melody Release Notes for AVR MCU Family Support

Configurator Importer | AVR Freaks

 

"Dare to be naïve." - Buckminster Fuller

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

No one knows what is hiding behind 'atmel_start_init()', but if interrupts are not enabled ( sei() ), no interrupts.