interfacing two pcf8574 with atmega32

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

I have a project running on one pcf8574 already,with no problem , now I want to add a BackPack pcf8574 to this project.,which is also working on its own with no problem.

So I have mixed the two main.c together,but It seems that I can not tell the project where to find the right files,therefor stopping the errors coming up. 

This is my out put file for you see,and tell me where I am wrong.

 

------ Build started: Project: Expantion board.lcd, Configuration: Release AVR ------
Build started.
Project "Expantion board.lcd.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "E:\Atmel\7.0\Vs\Compiler.targets" from project "E:\AtmelStudio\7.0\AZ108B.Projects\Expantion board.lcd\Expantion board.lcd\Expantion board.lcd.cproj" (target "Build" depends on it):
    Task "RunCompilerTask"
        Shell Utils Path E:\AtmelStudio\7.0\AZ108B.Projects
        E:\Atmel\7.0\shellUtils\make.exe all --jobs 4 --output-sync 
        Building target: Expantion board.lcd.elf
        Invoking: AVR/GNU Linker : 5.4.0
        main.o: In function `main':
E:\AtmelStudio\7.0\AZ108B.Projects\Expantion board.lcd\Expantion board.lcd\Release\main.c(1,1): error: undefined reference to `lcd_init'
E:\AtmelStudio\7.0\AZ108B.Projects\Expantion board.lcd\Expantion board.lcd\Release\main.c(1,1): error: undefined reference to `lcd_home'
E:\AtmelStudio\7.0\AZ108B.Projects\Expantion board.lcd\Expantion board.lcd\Release\main.c(1,1): error: undefined reference to `lcd_led'
collect2.exe(0,0): error: ld returned 1 exit status
        make: *** [Expantion board.lcd.elf] Error 1
        "E:\Atmel\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe" -o "Expantion board.lcd.elf"  main.o   -Wl,-Map="Expantion board.lcd.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,-L"../../../lcdpcf8574/src/lcdpcf8574" -Wl,-L"../../../lcdpcf8574/lcdpcf8574" -Wl,-L"../../../lcdpcf8574/src/uart" -Wl,-L"../../../lcdpcf8574/src/pcf8574" -Wl,-L"../../../../toolchain/avr8/avr8-gnu-toolchain/lib"  -Wl,--gc-sections -mmcu=atmega32a -B "E:\Atmel\7.0\Packs\Atmel\ATmega_DFP\1.4.351\gcc\dev\atmega32a"  
E:\AtmelStudio\7.0\AZ108B.Projects\Expantion board.lcd\Expantion board.lcd\Release\Makefile(106,1): error: recipe for target 'Expantion board.lcd.elf' failed
        The command exited with code 2.
    Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "Expantion board.lcd.cproj" -- FAILED.
Done building project "Expantion board.lcd.cproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
 

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

The first error says it all- you’ve called a function lcd_init() but the compiler can’t find it. Where does this function live and how have you told the compiler to find it? It might be time to do a little research on how the compiler works with multiple files and how to tell AS7 to do this. Once you’ve got this knowlege, you’ll be able to solve and avoid further problems.

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

Attach or paste your new main.c

 

Then we can show you how to use in an AS7.0 project.

 

David.

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

Thank you David for your help .

Sorry David,its a bit long and complicated.

This is my new main.c

 

/*
 * Expantion board.lcd.c
 *
 * Created: 20/02/1399 04:10:15 ب.ظ
 * Author : Aziz
 */
#include <avr/io.h>
#include <stdio.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#define F_CPU 8000000
#include <util/delay.h>
#include "lcdpcf8574.h"//
//#include "lcdpcf8574.c"
#define UART_BAUD_RATE 2400
#include "uart.h"//"uart/uart.h"
#define PIN(C) (*(&C - 2))    /* address of input register of port x */
//=========================================================================================
#include "avr/eeprom.h"
#include <az108.h>
#define L6  SBIT(PINA,5) // (AUX)doshakhe darb
#define L7  ((TWDR)&(0x04)) //(CBD)ghofle darbe cabinSBIT(PINA,6)//
#define L8  ((TWDR)&(0x08)) //(DFC)ghofle darbe tabaghat(nor)SBIT(PINA,7)//
#if LCD_LINES==1
#define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_4BIT_1LINE
#else
#define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_4BIT_2LINES
#endif
//======================================================
/*
lcdpcf8574 lib 0x03

copyright (c) Davide Gironi, 2013

Released under GPLv3.
Please refer to LICENSE file for licensing information.
*/

#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>

#include "../pcf8574/pcf8574.h"

#include "lcdpcf8574.h"

#define lcd_e_delay()   __asm__ __volatile__( "rjmp 1f\n 1:" );
#define lcd_e_toggle()  toggle_e()

#if LCD_LINES==1
#define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_4BIT_1LINE
#else
#define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_4BIT_2LINES
#endif

volatile uint8_t dataport = 0;


Last Edited: Sun. May 10, 2020 - 10:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you Kartman ,

I will certainly study those content and try to understand.

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

@Aziz,

 

You have an unholy mess.    And it is a nightmare to copy-paste such a large amount of code from the Forum.   It is easier to attach as .C or a .ZIP file.

 

But I suggest that you explain what you want to do in English.

Then we can help you to design the project before any actual code is written.

 

David.

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

Ok.Lets put it this way:

A main.c file is working with pcf8574 for expanding the ports, now I want to add another BackPack lcd pcf8574 (which that is also wroking ok on on its own),So the question is :

How to add this last addition to my main.c file which I already had,  and build it so that both can be put to service.

The address of pcf8574 is 0x40,

The address of  BackPack.lcd8574 is 0x27.

Am I clear about what I want to do?

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

The address of pcf8574 is 0x40,       this is 8-bit address

The address of  BackPack.lcd8574 is 0x27.   this is 7-bit address

 

The Gironi functions expect 7-bit address.  Or device index e.g. #0 for 0x20,  #7 for 0x27

 

#include <util/delay.h>             //for _delay_ms()

#include "lcdpcf8574/lcdpcf8574.h"  //for 16x2 LCD functions
#include "pcf8574/pcf8574.h"        //for regular PCF8574 functions

int main(void)
{
    pcf8574_init();                //all PCF chips
    lcd_init(LCD_DISP_ON_BLINK);   //Slave address = 0x27
    lcd_gotoxy(0, 0);   //set cursor
    lcd_puts("Hello Aziz");
    while(1) {
        int i = 0;
        for(i=0; i<8; i++) {
            // your PCF8574 chip has address 0x20.  i.e. device=0
            pcf8574_setoutputpins(0, i, 1, 0); //set one expander bit lo
            _delay_ms(100);
            pcf8574_setoutputpins(0, i, 1, 1); //set hi
            _delay_ms(100);
        }
    }
}

I attach the AS7.0 solution with the new project.

 

Note that the main file is in the project directory but the Gironi files are in your original src directory.

The Project Properties set F_CPU value and search directory for the Gironi files

 

If you attach 8 active-low LEDs to the expander pins,  they should blink in sequence.

The PCF can not source current.  So active-high LEDs will not work.

 

David.

Attachment(s): 

Last Edited: Sun. May 10, 2020 - 02:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you David, its very nice of you, 

It works pretty well and  am enjoying  manipulating with it.

I am just wondering how it is working ,now we have one main.c in the project and one main.c you pasted in your Answer,when I built the main.c in the project,I think three hex file was out ,one in the aziz_backpack,

one in the aziz_expantion,and the last in the aziz_uno.

Q1. Do we need aziz_uno at all?

Q2-which main.c should I  modify and add to that long program of mine?  

Q3- The main.c which you pasted ,I didn;t build,how did it come in the program?

 

Many more Thanks for your time and care.

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

If you attach your long program as a .C or .ZIP,  I might create another AS7.0 project.

 

But first you need to see how the existing project works.

i.e. which files are compiled.   where the files are located.    where the .O files are built.

i.e. how the Project Properties are configured.

 

David.

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

Kartman wrote:
The first error says it all- you’ve called a function lcd_init() but the compiler can’t find it.

Indeed.  (well, actually the Linker - not the Compiler)

 

But we've covered all this before in the OP's previous thread:

 

https://www.avrfreaks.net/commen...

 

https://www.avrfreaks.net/commen...

 

 

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. May 11, 2020 - 07:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks David,

david.prentice wrote:

If you attach your long program as a .C or .ZIP,  I might create another AS7.0 project.

 

  Here is my zip file.

Attachment(s): 

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

I have made a project that when it is  compiled, no error is reported,but when build ,although  there is no error ,but only warnings,build fails and there is no out put hex files.

here is the out put file:

 

------ Rebuild All started: Project: EDAZ108B.H8T.Dar, Configuration: Release AVR ------
Build started.
Project "EDAZ108B.H8T.Dar.cproj" (Clean target(s)):
Target "Clean" in file "E:\AtmelStudio\7.0\Vs\Compiler.targets" from project "E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDAZ108B.H8T.Dar.cproj" (entry point):
    Task "RunCompilerTask"
        Shell Utils Path E:\AtmelStudio\7.0\AZ108B.Projects
        E:\AtmelStudio\7.0\shellutils\make.exe clean 
        rm -rf  EDH8TDBL.o H8TDBL.o main.o   
        rm -rf  EDH8TDBL.d H8TDBL.d main.d   
        rm -rf "EDAZ108B.H8T.Dar.elf" "EDAZ108B.H8T.Dar.a" "EDAZ108B.H8T.Dar.hex" "EDAZ108B.H8T.Dar.lss" "EDAZ108B.H8T.Dar.eep" "EDAZ108B.H8T.Dar.map" "EDAZ108B.H8T.Dar.srec" "EDAZ108B.H8T.Dar.usersignatures"
    Done executing task "RunCompilerTask".
Done building target "Clean" in project "EDAZ108B.H8T.Dar.cproj".
Done building project "EDAZ108B.H8T.Dar.cproj".

Build succeeded.
------ Rebuild All started: Project: EDAZ108B.H8T.Dar, Configuration: Release AVR ------
Build started.
Project "EDAZ108B.H8T.Dar.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "E:\AtmelStudio\7.0\Vs\Compiler.targets" from project "E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDAZ108B.H8T.Dar.cproj" (target "Build" depends on it):
    Task "RunCompilerTask"
        Shell Utils Path E:\AtmelStudio\7.0\AZ108B.Projects
        E:\AtmelStudio\7.0\shellutils\make.exe all --jobs 4 --output-sync 
        make: *** No rule to make target '.././H8TDBL.c', needed by 'H8TDBL.o'.  Stop.
        make: *** Waiting for unfinished jobs....
        Building file: .././EDH8TDBL.c
        Invoking: AVR/GNU C Compiler : 5.4.0
        .././EDH8TDBL.c: In function 'timer':
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(59,3): warning: implicit declaration of function 'delay_ms' [-Wimplicit-function-declaration]
           delay_ms(t1);
           ^
        .././EDH8TDBL.c: At top level:
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(91,6): warning: conflicting types for 'delay_ms'
         void delay_ms( int ms )
              ^
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(59,3): info: previous implicit declaration of 'delay_ms' was here
           delay_ms(t1);
           ^
        .././EDH8TDBL.c: In function 'manual':
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(235,2): warning: implicit declaration of function 'detect' [-Wimplicit-function-declaration]
          detect();
          ^
        .././EDH8TDBL.c: At top level:
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(237,6): warning: conflicting types for 'detect'
         void detect(void)
              ^
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(235,2): info: previous implicit declaration of 'detect' was here
          detect();
          ^
        .././EDH8TDBL.c: In function 'detect':
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(265,6): warning: implicit declaration of function 'normal' [-Wimplicit-function-declaration]
              normal();
              ^
        "E:\AtmelStudio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DNDEBUG  -I"../../../../toolchain/avr8/avr8-gnu-toolchain/include"  -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -mmcu=atmega32a -B "E:\AtmelStudio\7.0\Packs\Atmel\ATmega_DFP\1.4.351\gcc\dev\atmega32a" -c -std=gnu99 -MD -MP -MF "EDH8TDBL.d" -MT"EDH8TDBL.d" -MT"EDH8TDBL.o"   -o "EDH8TDBL.o" ".././EDH8TDBL.c" 
        Finished building: .././EDH8TDBL.c
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(239,10): warning: variable 's' set but not used [-Wunused-but-set-variable]
          int seg,s;
                  ^
        .././EDH8TDBL.c: At top level:
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(694,6): warning: conflicting types for 'normal'
         void normal(void)
              ^
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(265,6): info: previous implicit declaration of 'normal' was here
              normal();
              ^
        .././EDH8TDBL.c: In function 'normal':
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(727,6): warning: implicit declaration of function 'updown' [-Wimplicit-function-declaration]
              updown();
              ^
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(696,16): warning: variable 'e' set but not used [-Wunused-but-set-variable]
          int f=0,s,seg,e;
                        ^
        .././EDH8TDBL.c: At top level:
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(922,6): warning: conflicting types for 'updown'
         void updown(void)
              ^
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(727,6): info: previous implicit declaration of 'updown' was here
              updown();
              ^
        .././EDH8TDBL.c: In function 'updown':
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(929,4): warning: 's' is used uninitialized in this function [-Wuninitialized]
          if(s<e) //------------UP
            ^
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(929,4): warning: 'e' is used uninitialized in this function [-Wuninitialized]
        .././EDH8TDBL.c: In function 'normal':
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(913,7): warning: 'seg' is used uninitialized in this function [-Wuninitialized]
          PORTD=seg;
               ^
        .././EDH8TDBL.c: In function 'updown':
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(1181,5): warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
           if(b==1)
             ^
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(1366,10): warning: 'seg' may be used uninitialized in this function [-Wmaybe-uninitialized]
             PORTD=seg;
                  ^
        .././EDH8TDBL.c: In function 'normal':
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(709,8): warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
              if(s!=1) //no unneccery call button is on
                ^
        .././EDH8TDBL.c: In function 'detect':
E:\AtmelStudio\7.0\AZ108B.Projects\EDAZ108B.H8T.Dar\ED\EDH8TDBL.c(622,8): warning: 'seg' may be used uninitialized in this function [-Wmaybe-uninitialized]
           PORTD=seg;
                ^
    Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "EDAZ108B.H8T.Dar.cproj" -- FAILED.
Done building project "EDAZ108B.H8T.Dar.cproj" -- FAILED.

Build FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

 

Will you please say whats wrong?

 

Last Edited: Thu. May 14, 2020 - 07:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azizollah wrote:
there is no error
I beg to differ:

        E:\AtmelStudio\7.0\shellutils\make.exe all --jobs 4 --output-sync 
        make: *** No rule to make target '.././H8TDBL.c', needed by 'H8TDBL.o'.  Stop.

Are you using an "external  makefile" by any chance?

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

I don;t know what "external makefile" is.

I don;t think I have  .

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

azizollah wrote:
only warnings

Warnings may still lead to a build failing.

 

Fix the warnings!

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...