Пример #1
0
void hd44780_init() {
	
	data[0] = 0x00 | backlight;
	data[1] = 0x00 | backlight;

	// Reset all
	I2C_Master_BufferWrite(I2C1, data, 1, Polling, hd44780_address << 1);

	hd44780_cmd(0x03);
	delay_us(5000);
	hd44780_cmd(0x03);
	delay_us(100);
	hd44780_cmd(0x02);
	delay_us(200);

	hd44780_cmd(0x28); // 4 bit mode
	hd44780_cmd(0x06); // set direction of cursor to right
	hd44780_cmd(0x01); // clear display, go to 0x0
	hd44780_cmd(0x0E); // turn on display, set solid cursor
	hd44780_cmd(0x0C); // turn on display, set invisiblecursor

	hd44780_cgram_write(0, (u8[]){0,10,31,31,14,4,0,0});
	hd44780_cgram_write(1, (u8[]){0,10,21,17,10,4,0,0});

	hd44780_cmd(0x01); // clear display, go to 0x0

}
Пример #2
0
void ad5934_write_data(int addr, int data) {
    uint8_t buf[2];
    buf[0] = addr;	// AD5934 register address to be written
    buf[1] = data;	// register data to be written
    I2C_Master_BufferWrite(EVAL0349_I2CX,buf,2,DMA, AD5934_ADDR);

}
Пример #3
0
uint8_t SENSOR9AXIS_Read_Bytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data)
{
    /*
     * devAddr should be shifted 1 bit to left ...
     */
    
    Status  i2cRW_status;

    /* Disable FSMC */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, DISABLE);

    Buffer_Tx1[0] = regAddr;

    i2cRW_status = I2C_Master_BufferWrite(I2C1, Buffer_Tx1, 1, Interrupt, devAddr << 1);
    if(Error == i2cRW_status)
    {
        DEBUG_MSG_FUNC_ERROR;
        return 0;
    }

    i2cRW_status = I2C_Master_BufferRead(I2C1, data, length, Polling, devAddr << 1);
    if(Error == i2cRW_status)
    {
        DEBUG_MSG_FUNC_ERROR;
        return 0;
    }

    /* Enable FSMC */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

    return length;
}
Пример #4
0
//读取MPU6050 I2C Slave0 的数据
int MPU6050_Read_Ext_Sens_Data(uint8_t RegAddr,uint8_t *buff, uint8_t length)
{
	Status rtn;
	IIC_Buffer_Tx[0] = RegAddr;  
	rtn = I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,1,Polling, MPU6050_Addr);
	rtn = I2C_Master_BufferRead(MPU6050_I2C, buff,length,Polling, MPU6050_Addr);
	return rtn;
}
Пример #5
0
//**************************************
//读指定地址数据
//**************************************
uint16_t MPU6050_GetData(uint8_t REG_Address)
{
	Status rtn;
	char H,L;
	//H=Single_ReadI2C(REG_Address);
		IIC_Buffer_Tx[0]=REG_Address;
	  I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,1,Polling, MPU6050_Addr);
		rtn=I2C_Master_BufferRead(MPU6050_I2C,IIC_Buffer_Rx,1,Polling, MPU6050_Addr);	
		if(rtn == Success) H=IIC_Buffer_Rx[0];
		else H=0;
	//L=Single_ReadI2C(REG_Address+1);
		IIC_Buffer_Tx[0]=REG_Address+1;
	  I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,1,Polling, MPU6050_Addr);
		rtn=I2C_Master_BufferRead(MPU6050_I2C,IIC_Buffer_Rx,1,Polling, MPU6050_Addr);
		if(rtn == Success) L=IIC_Buffer_Rx[0];
		else L=0;
	return (H<<8)+L;   //合成数据
}
Пример #6
0
uint8_t at24c64_read_bytes(uint16_t address, uint8_t *data, uint16_t n) {
    tx = (uint8_t*)malloc(2 * sizeof(uint8_t));
    tx[0] = address << 8;
    tx[1] = 0x00FF & address;
    I2C_Master_BufferWrite(I2C1, tx, 2, Polling, AT24C64_ADDRESS << 1);
    I2C_Master_BufferRead(I2C1, data, n, Polling, AT24C64_ADDRESS << 1);

    free(tx);
    return 0;
}
Пример #7
0
// init ADG715 switch to use for EC or Temp measurements, or EC or Temp calibration
void init_adg715(uint8_t mode) {
    range_mode = mode;
    adg_conf[0] = mode;
    uint8_t i=0;
    // write config
    I2C_Master_BufferWrite(EVAL0349_I2CX,adg_conf,1,Polling, ADG715_ADDR);
    Delay_us_(100000);
    // and read it back for assurance. Could be disabled to enhance the speed
    I2C_Master_BufferRead(EVAL0349_I2CX, adg_conf, 1,DMA,ADG715_ADDR);
    Delay_us_(100000);
}
Пример #8
0
void hd44780_send(u8 cmd, bool set_rs) {
    u8 rs_ = 0;
    if (set_rs)
    	rs_ = rs;

    hd44780_data[0] = (cmd & 0xF0) | backlight | en | rs_;
    hd44780_data[1] = (cmd & 0xF0) | backlight;
    hd44780_data[2] = (cmd & 0x0F) << 4 | backlight | en | rs_;
    hd44780_data[3] = (cmd & 0x0F) << 4 | backlight;
    I2C_Master_BufferWrite(I2C1, hd44780_data, 4, Polling, hd44780_address << 1);
}
Пример #9
0
// set pointer and read the data from AD5934
uint8_t ad5934_read_data(int addr) {
    uint8_t buf[2];
    buf[0] = AD5934_SET_ADDR_PNTR;
    buf[1] = addr;

    // send Set Pointer command to AD5934
    I2C_Master_BufferWrite(EVAL0349_I2CX,buf,2,DMA, AD5934_ADDR);

    Delay_us_(1000);
    // Read the data from AD5934. It sends the data from the register address with pointer set
    I2C_Master_BufferRead(EVAL0349_I2CX, buf, 1,DMA,AD5934_ADDR);
    vTaskDelay(50);
    return buf[0];
}
Пример #10
0
uint8_t at24c64_write_bytes(uint16_t address, uint8_t *data, uint16_t n) {
    // Note: After writing any data to module, you have to wait t_WR until
    // read will be possible (10 ms). ACK Polling is allowed (check datasheet)
    tx = (uint8_t*)malloc((n + 2) * sizeof(uint8_t));

    tx[0] = address << 8;
    tx[1] = 0x00FF & address;
    memcpy(&tx[2], data, n);

    I2C_Master_BufferWrite(I2C1, tx, n + 2, Polling, AT24C64_ADDRESS << 1);

    free(tx);
    return 0;
}
Пример #11
0
//**************************************
//初始化MPU6050
//**************************************
int InitMPU6050()
{
	Status rtn;
	//Single_WriteI2C(PWR_MGMT_1, 0x00);	//解除休眠状态
	IIC_Buffer_Tx[0]=PWR_MGMT_1;
	IIC_Buffer_Tx[1]=0x01;
  rtn=I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,2,Polling, MPU6050_Addr);
	
	//Single_WriteI2C(SMPLRT_DIV, 0x07);
	IIC_Buffer_Tx[0]=SMPLRT_DIV;
	IIC_Buffer_Tx[1]=0x31;
  rtn=I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,2,Polling, MPU6050_Addr);
	
	
	//Single_WriteI2C(MPU6050_CONFIG, 0x06);
	IIC_Buffer_Tx[0]=MPU6050_CONFIG;
	IIC_Buffer_Tx[1]=0x06;
  rtn=I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,2,Polling, MPU6050_Addr);
	
	//Single_WriteI2C(GYRO_CONFIG, 0x18);
	IIC_Buffer_Tx[0]=GYRO_CONFIG;
	IIC_Buffer_Tx[1]=0x18;
  rtn=I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,2,Polling, MPU6050_Addr);
	
	//Single_WriteI2C(ACCEL_CONFIG, 0x01);
	IIC_Buffer_Tx[0]=ACCEL_CONFIG;
	IIC_Buffer_Tx[1]=0x01;
  rtn=I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,2,Polling, MPU6050_Addr);
	
	//配置Motion Interrupt
	//Single_WriteI2C(ACCEL_CONFIG, 0x01);
	IIC_Buffer_Tx[0]=0x38;
	IIC_Buffer_Tx[1]=0x41;
  rtn=I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,2,Polling, MPU6050_Addr);
	
	//Single_WriteI2C(ACCEL_CONFIG, 0x01);
	IIC_Buffer_Tx[0]=0x1F;
	IIC_Buffer_Tx[1]=0x05;
  rtn=I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,2,Polling, MPU6050_Addr);
	
	//Single_WriteI2C(ACCEL_CONFIG, 0x01);
	IIC_Buffer_Tx[0]=0x20;
	IIC_Buffer_Tx[1]=0x07;
  rtn=I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,2,Polling, MPU6050_Addr);
	
	return !rtn;
}
Пример #12
0
void hd44780_init(TIM_TypeDef *t) {
    timer = t;
    // Setup clock
    setup_delay_timer(timer);

    hd44780_data[0] = 0x00 | backlight;
    hd44780_data[1] = 0x00 | backlight;

    // Init I2C
    I2C_LowLevel_Init(I2C1);

    // Reset all
    I2C_Master_BufferWrite(I2C1, hd44780_data, 1, Polling, hd44780_address << 1);

    hd44780_cmd(0x03);
    delay_us(timer, 5000);
    hd44780_cmd(0x03);
    delay_us(timer, 100);
    hd44780_cmd(HD44780_MOVE_TO_HOME);
    delay_us(timer, 200);

    hd44780_cmd(0x28); // 4 bit mode
    hd44780_cmd(0x06); // set direction of cursor to right
    hd44780_cmd(HD44780_DISPLAY_ERASE); // clear display, go to 0x0
//    hd44780_cmd(0x0E); // turn on display, set solid cursor
    hd44780_cmd(HD44780_DISPLAY_SHOW); // turn on display, set invisiblecursor

//    u8 arr[] = {0,10,31,31,14,4,0,0};
//    u8 arr2[]= {0,10,21,17,10,4,0,0};

//    hd44780_cgram_write(0, arr);
//    hd44780_cgram_write(1, arr2);

    hd44780_cmd(0x01); // clear display, go to 0x0

//    hd44780_backlight(initial_backlight);
//    hd44780_print("Linia 0");
//    hd44780_go_to_line(1);
//    hd44780_print("Linia 1");
//    hd44780_go_to_line(2);
//    hd44780_print("Linia 2");
//    hd44780_go_to_line(3);
//    hd44780_print("Linia 3");

//    hd44780_char(0);
//    hd44780_char(1);
}
Пример #13
0
//**************************************
//连续读ax,ay,az,temperature,gx,gy,gz数据
//**************************************
int MPU6050_ReadRawData(struct MPU6050_RawData_s *s_IMUVar)
{
	Status rtn;
	char H,L;

	IIC_Buffer_Tx[0]=ACCEL_XOUT_H;
  I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,1,Polling, MPU6050_Addr);
	rtn=I2C_Master_BufferRead(MPU6050_I2C,IIC_Buffer_Rx,14,Polling, MPU6050_Addr);	
	if(rtn == Success) 
	{
		H=IIC_Buffer_Rx[0];
		L=IIC_Buffer_Rx[1];
		s_IMUVar->ax = (H<<8)+L;
		
		H=IIC_Buffer_Rx[2];
		L=IIC_Buffer_Rx[3];
		s_IMUVar->ay = (H<<8)+L;
		
		H=IIC_Buffer_Rx[4];
		L=IIC_Buffer_Rx[5];
		s_IMUVar->az = (H<<8)+L;
		
		H=IIC_Buffer_Rx[6];
		L=IIC_Buffer_Rx[7];
		s_IMUVar->temperature = (H<<8)+L;
		
		H=IIC_Buffer_Rx[8];
		L=IIC_Buffer_Rx[9];
		s_IMUVar->gx = (H<<8)+L;
		
		H=IIC_Buffer_Rx[10];
		L=IIC_Buffer_Rx[11];
		s_IMUVar->gy = (H<<8)+L;
		
		H=IIC_Buffer_Rx[12];
		L=IIC_Buffer_Rx[13];
		s_IMUVar->gz = (H<<8)+L;

	}
	return !rtn;
}
Пример #14
0
int stm32_i2c_write(unsigned char slave_addr,
                     unsigned char reg_addr,
                     unsigned char length,
                     unsigned char const *data)
{
    unsigned char i;
		Status rtn;
    if (!length)
        return 0;
		
		if(length > 24) return -1;
		
		IIC_Buffer_Tx[0] = reg_addr;
		for(i=0;i<length;i++)
		{
			IIC_Buffer_Tx[i+1]=data[i];
		}
		rtn=I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,length+1,Polling, slave_addr);
    if(rtn==Success)return 0;
		else return -1;
}
Пример #15
0
int8_t SENSOR9AXIS_Write_Bytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data)
{
    Status  i2cRW_status;

    /* Disable FSMC */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, DISABLE);

    Buffer_Tx1[0] = regAddr;
    memcpy(&Buffer_Tx1[1], data, length);

    i2cRW_status = I2C_Master_BufferWrite(I2C1, Buffer_Tx1, length + 1, Interrupt, devAddr << 1);
    if(Error == i2cRW_status)
    {
        DEBUG_MSG_FUNC_ERROR;
        return -1;
    }

    /* Enable FSMC */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

    return 0;
}
Пример #16
0
int stm32_i2c_read(unsigned char slave_addr,
                    unsigned char reg_addr,
                    unsigned char length,
                    unsigned char *data)
{
		Status rtn;
    if (!length)
        return 0;

		rtn=I2C_Master_BufferWrite(MPU6050_I2C, &reg_addr,1,Polling, slave_addr);
		if(rtn!=Success) return -1;
		rtn=I2C_Master_BufferRead(MPU6050_I2C, (uint8_t*)data,length,Polling, slave_addr);
    if(rtn==Success)
		{
			
			return 0;
		}
		else 
		{
			return -1;
		}
}
Пример #17
0
void hd44780_backlight(bool new_value) {
    backlight = new_value << 3;
    I2C_Master_BufferRead(I2C1, hd44780_data, 1, Polling, hd44780_address << 1);
    hd44780_data[0] |= backlight;
    I2C_Master_BufferWrite(I2C1, hd44780_data, 1, Polling, hd44780_address << 1);
}
Пример #18
0
//-----------------------------------------------------------------------------
// Helper function that is used to write to the part which abstracts what
// bus mode is currently being used.
//-----------------------------------------------------------------------------
static uint32_t si47xx_lowWrite(u8 number_bytes, u8 *data_out)
{
	return I2C_Master_BufferWrite(I2C1, data_out,  number_bytes, /*Interrupt*/Polling, SI47XX_ADDR);
	//I2C_Master_BufferWrite(I2C1, Buffer_Tx1,120,Interrupt, 0x28);
}