IS31F3729驱动程序,用的是CH32V103的I2C1

本文详细介绍了如何在CH32V103单片机上通过I2C1接口驱动IS31F3729芯片。内容涵盖了I2C通信协议的基础知识,IS31F3729的功能特性,以及具体的驱动程序编写步骤和示例代码,为嵌入式硬件开发者提供了实用的参考资料。
摘要由CSDN通过智能技术生成

 

#include "debug.h"
#include "string.h"
#include <stdlib.h>


/* DATA ADDRESS Length Definition */
#define Address_8bit  0
#define Address_16bit  1

/* DATA ADDRESS Length Selection */
#define Address_Lenth   Address_8bit
//#define Address_Lenth   Address_16bit


#define  X_LED  (6)  //横向LED数量
#define  Y_LED  (15) //纵向LED数量
#define  SCALINGS (15) //scaling数量
#define DATA_MAX 60//(X_LED*Y_LED)

#define DATA_SIZE sizeof(data[DATA_MAX])
#define DEVICE1  0
#define DEVICE2  1
typedef struct{
   u8 B;
   u8 G;
   u8 R;
}RGB_LED;
RGB_LED data[DATA_MAX];

/*******************************************************************************
* Function Name  : IS31F3729_I2c_Init
* Description    : Initializes the IIC peripheral.
* Input          : None
* Return         : None
********************************************************************************/
void IS31F3729_I2c_Init( u32 bound, u16 address)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    I2C_InitTypeDef I2C_InitTSturcture;

    RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE );
    GPIO_PinRemapConfig(GPIO_Remap_I2C1, ENABLE);
    RCC_APB1PeriphClockCmd( RCC_APB1Periph_I2C1, ENABLE );


    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init( GPIOB, &GPIO_InitStructure );

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init( GPIOB, &GPIO_InitStructure );

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init( GPIOB, &GPIO_InitStructure );
    GPIO_SetBits(GPIOB, GPIO_Pin_6);     //拉高使能脚

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init( GPIOC, &GPIO_InitStructure );
    GPIO_ResetBits(GPIOC, GPIO_Pin_13);


    I2C_InitTSturcture.I2C_ClockSpeed = bound;
    I2C_InitTSturcture.I2C_Mode = I2C_Mode_I2C;
    I2C_InitTSturcture.I2C_DutyCycle = I2C_DutyCycle_2;
    I2C_InitTSturcture.I2C_OwnAddress1 = address;
    I2C_InitTSturcture.I2C_Ack = I2C_Ack_Enable;
    I2C_InitTSturcture.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_Init( I2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值