Data send-receive by IIC-bus Hardware: IIC-board with 4 x PCF8574 IC you see a 8bit leds this leds show the value from an other 8574 who has 8 switches as input The 8xswitches from IIC you can see also at the pins PC_0 to PC_7

Dependencies:   mbed

Thats my logo Brandenkopf tower Black forest Germany: /media/uploads/schlaumaier54/funkturm.jpg

This is my hardware:

/media/uploads/schlaumaier54/nucleof103_3platinen.jpg

This is a farmer house in the black forest: /media/uploads/schlaumaier54/bauernhaus.jpg

And this is a screenshot of a PWM Signal.

The sinus signal is the result whe nyou give the PWM to a R-C circuit:

/media/uploads/schlaumaier54/img_20171201_152937859.jpg

And in the middle of the three grazy persons: That`s my person:

/media/uploads/schlaumaier54/neumaier_europark.jpg

Neumaier Feb 2018

Committer:
schlaumaier54
Date:
Fri Aug 21 11:40:23 2015 +0000
Revision:
0:b183e63b31f8
Data send-receive by IIC-bus Hardware: IIC-board with 4 x PCF8574 IC; you see a 8bit leds this leds show the value from an other 8574 who has 8 switches as input; The 8xswitches from IIC you can see also at the pins PC_0 to PC_7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
schlaumaier54 0:b183e63b31f8 1 /*Data send-receive by IIC-bus Hardware: IIC-board with 4 x PCF8574 IC
schlaumaier54 0:b183e63b31f8 2 you see a 8bit leds this leds show the value from an other 8574 who has 8 switches as input
schlaumaier54 0:b183e63b31f8 3 The 8xswitches from IIC you can see also at the pins PC_0 to PC_7
schlaumaier54 0:b183e63b31f8 4 Tasks: 1. Receive a analog value and show this value as a 8xled-strip at the third PCF8574 IC
schlaumaier54 0:b183e63b31f8 5 2. Send the 8xswitches from IIC-bus to the virtuell COM-port. You can visualize the switches
schlaumaier54 0:b183e63b31f8 6 with the Software "Profilab" or "LABview"
schlaumaier54 0:b183e63b31f8 7 Aug. 2015 G. Neumaier Gewerblich-Technische Schule Offenburg Germany
schlaumaier54 0:b183e63b31f8 8 */
schlaumaier54 0:b183e63b31f8 9
schlaumaier54 0:b183e63b31f8 10 #include "mbed.h"
schlaumaier54 0:b183e63b31f8 11 #define PCF8574_ADDRoutput 0x46 // PCF8574 address 0x46 lowest bit (R/W)=0 IICboard P3
schlaumaier54 0:b183e63b31f8 12 #define PCF8574_ADDRinput 0x45 // PCF8574 address 0x44 lowest bit (R/W)=0 IICboard P2
schlaumaier54 0:b183e63b31f8 13 //ADR-Jumper on IIC4xPCF8574board jumped to 0: Basis ADR:P0=0x40;P1=0x42;P2=0x44;P3=0x46;
schlaumaier54 0:b183e63b31f8 14 //ADR-Jumper on IIC4xPCF8574board jumped to 1: Basis ADR:P0=0x48;P1=0x4A;P2=0x4C;P3=0x4E;
schlaumaier54 0:b183e63b31f8 15 #define LED_MASK 0xffff //Portc has 16bit, therefore 4digit mask
schlaumaier54 0:b183e63b31f8 16 // 1=output 0=input
schlaumaier54 0:b183e63b31f8 17
schlaumaier54 0:b183e63b31f8 18 I2C i2c(I2C_SDA, I2C_SCL); //IIC Pins SDA and SCL for ARDUINO pinheader Nucleo-board
schlaumaier54 0:b183e63b31f8 19 //SCL and SPA pullup resistors 2k2Ohm to+5Volt
schlaumaier54 0:b183e63b31f8 20
schlaumaier54 0:b183e63b31f8 21 PortOut leds(PortC, LED_MASK); //Important: Port_B not possible -> PB_8 PB_9 Pins for IIC-bus
schlaumaier54 0:b183e63b31f8 22
schlaumaier54 0:b183e63b31f8 23 DigitalOut myled(LED1); //LED on Nucleo-board
schlaumaier54 0:b183e63b31f8 24 //for the task1****: AnalogIn analog_value0(A0); //same as Pin PA_0
schlaumaier54 0:b183e63b31f8 25 //for the task2****: Serial pc(SERIAL_TX, SERIAL_RX);
schlaumaier54 0:b183e63b31f8 26
schlaumaier54 0:b183e63b31f8 27 int main()
schlaumaier54 0:b183e63b31f8 28 {
schlaumaier54 0:b183e63b31f8 29 char input8bit;
schlaumaier54 0:b183e63b31f8 30 char data_write[2]; //must be char!!
schlaumaier54 0:b183e63b31f8 31 char data_read[2]; //read buffer
schlaumaier54 0:b183e63b31f8 32
schlaumaier54 0:b183e63b31f8 33 data_write[0] = 0xf2; //LEDs low aktiv dummy
schlaumaier54 0:b183e63b31f8 34 int status = i2c.write(PCF8574_ADDRoutput , data_write, 1, 0);
schlaumaier54 0:b183e63b31f8 35 if (status != 0) // Error no acknowledge detected
schlaumaier54 0:b183e63b31f8 36 {
schlaumaier54 0:b183e63b31f8 37 while (1) //-> endless loop when error no IIC-IC detected
schlaumaier54 0:b183e63b31f8 38 {
schlaumaier54 0:b183e63b31f8 39 myled = !myled;
schlaumaier54 0:b183e63b31f8 40 wait(0.7);
schlaumaier54 0:b183e63b31f8 41 }
schlaumaier54 0:b183e63b31f8 42 }
schlaumaier54 0:b183e63b31f8 43
schlaumaier54 0:b183e63b31f8 44 while (1) //endless loop
schlaumaier54 0:b183e63b31f8 45 {
schlaumaier54 0:b183e63b31f8 46
schlaumaier54 0:b183e63b31f8 47 // i2c.read will start the IIC-bus with the last 0 also stop the same by 12c.read
schlaumaier54 0:b183e63b31f8 48 i2c.read(PCF8574_ADDRinput, data_read, 1, 0); // read to array 1byte stop
schlaumaier54 0:b183e63b31f8 49 input8bit = data_read[0]; //array value to variable
schlaumaier54 0:b183e63b31f8 50 leds = input8bit; //Output PortC low-byte
schlaumaier54 0:b183e63b31f8 51 data_write[0] = input8bit; //8bit analog-value to array
schlaumaier54 0:b183e63b31f8 52 i2c.write(PCF8574_ADDRoutput , data_write, 1, 0); // output array 1byte stop
schlaumaier54 0:b183e63b31f8 53 //you see a digital 8bit PCF8574 output (8xleds), received from PCF8574 input (8xswitsches)
schlaumaier54 0:b183e63b31f8 54
schlaumaier54 0:b183e63b31f8 55 //Here your solutions from task1 and 2:
schlaumaier54 0:b183e63b31f8 56 }
schlaumaier54 0:b183e63b31f8 57
schlaumaier54 0:b183e63b31f8 58 }
schlaumaier54 0:b183e63b31f8 59