1680 views|1 replies

410

Posts

3

Resources
The OP
 

[Rawpixel RVB2601 development board trial experience] External IO port chip PCF8574 test [Copy link]

 

On the expansion board designed in the previous article, the 8-bit IO port was expanded using PCF8574 with I2C communication. Now let’s test the input and output.

1. Hardware Circuit

The PA8 and PA9 I2C communication interfaces are used in the hardware circuit, and the PA31 interrupt interface is reserved.

1.1 Circuit diagram 1

P6/P7 driver LED indicator.

1.2. Button circuit

1.3. Board connection plug-in location

2. Procedure

2.1、pcf8574.c

//pcf8574.c
#include "board_config.h"
#include "drv/gpio_pin.h"
#include <drv/pin.h>
#include <aos/aos.h>
#include "stdio.h"
#include "drv/iic.h"

#define IIC_SLAVE_ADDR      0x21
#define IIC_MEM_ADDR        0x0010
#define IIC_IDX             0

static csi_iic_t master_iic;

static void pcf8574_pinmux_init(void)
{
    csi_pin_set_mux(PA8,  PA8_IIC0_SCL ); 
    csi_pin_set_mux(PA9, PA9_IIC0_SDA); 
}

int pcf8574_init(void)
{
	uint8_t write_data[1];
	csi_error_t ret;
	uint32_t num;
	uint32_t i;
	pcf8574_pinmux_init();
	
	ret = csi_iic_init(&master_iic, IIC_IDX);
	if (ret != CSI_OK) {
		printf("csi_iic_initialize error\n");  
		return -1;
	}
	/* config iic master mode */  
	ret = csi_iic_mode(&master_iic, IIC_MODE_MASTER);
	if (ret != CSI_OK) {
		printf("csi_iic_set_mode error\n");
		return -1;
	}
	/* config iic 7bit address mode */  
	ret = csi_iic_addr_mode(&master_iic, IIC_ADDRESS_7BIT);
	if (ret != CSI_OK) {
		printf("csi_iic_set_addr_mode error\n");
		return -1;
	}
	
	/* config iic standard speed*/  
	ret = csi_iic_speed(&master_iic, IIC_BUS_SPEED_STANDARD);
	if (ret != CSI_OK) {
		printf("csi_iic_set_speed error\n");
		return -1;
	}
	write_data[0]=0xff;
	csi_iic_master_send(&master_iic, IIC_SLAVE_ADDR, write_data, 1, 100);
}

void  pcf8574_test(void)
{
	uint8_t wdat[2];
	uint8_t rdat[2];
	uint8_t num;
	wdat[0]=0x7F;
	csi_iic_master_send(&master_iic, IIC_SLAVE_ADDR, wdat, 1, 100);

	aos_msleep(100);
	wdat[0]=0xBF;  
	csi_iic_master_send(&master_iic, IIC_SLAVE_ADDR, wdat, 1, 100);
	aos_msleep(100);
	num = csi_iic_master_receive(&master_iic, IIC_SLAVE_ADDR, rdat, 1, 100);
	printf("read key value=%x\n",rdat[0]);
}

2.2, main.c


#include <stdlib.h>
#include <string.h>
#include <aos/aos.h>
#include "aos/cli.h"
#include "main.h"
#include "app_init.h"
#include "oled.h"
#include "led.h"
#include "pcf8574.h"

#define TAG "app"

int main(void)
{
    board_yoc_init();
    LOGD(TAG, "%s\n", aos_get_app_version());
    oled_init();
	led_init();
	pcf8574_init();
    while (1) {
        //LOGD(TAG, "Hello world! YoC");
        //aos_msleep(1000);
		//led_test();
		pcf8574_test();
    }

    return 0;
}

3. Operation Results

3.1、LED lights up alternately

3.2. Key input test, serial port output

Latest reply

Using diffuser plates requires a lot of experience. Now I just want to finish the project with the existing resources. It’s a headache!  Details Published on 2022-4-3 19:39
 
 

6818

Posts

11

Resources
2
 
Using diffuser plates requires a lot of experience. Now I just want to finish the project with the existing resources. It’s a headache!
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list