📄 upsd_i2c.h
字号:
/*------------------------------------------------------------------------
uPSD_I2C.h
Version:
June 2004, Version 1.0 - Initial Version
Dependencies: None
Description:
This is the header file for the uPSD I2C Device Driver (upsd_i2c.c).
Copyright (c) 2004 ST Microelectronics
This example demo code is provided as is and has no warranty,
implied or otherwise. You are free to use/modify any of the provided
code at your own risk in your applications with the expressed limitation
of liability (see below) so long as your product using the code contains
at least one uPSD products (device).
LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR
AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-------------------------------------------------------------------------*/
#ifndef _TURBO_I2C_H_
#define _TURBO_I2C_H_
/*-------------------------------------------------------------------------
unsigned char upsd_i2c_init (unsigned int Bus_Freq,
unsigned char Slave_Addr
)
This function is used to initialize the I2C device with indicated
own device address and Bus Freqency. Must be called before other I2C driver
function.
Slave_Addr - unsigned char
- Slave address of I2C device.
Bus_Freq - unsigned int
- I2C bus frequency.
return value:
0: initiate successfully
1: Error entry parameter
-------------------------------------------------------------------------*/
unsigned char upsd_i2c_init (unsigned int Bus_Freq,
unsigned char Slave_Addr
);
/*-------------------------------------------------------------------------
unsigned char upsd_i2c_Master_Xmit (unsigned char Slave_Addr,
unsigned char* Data_Ptr,
unsigned char N)
This function is used to transmit special length of data to Slave, only for
I2C master.
Slave_Addr - unsigned char
- Slave address of I2C device.
Data_Ptr - unsigned char*
- address pointer of transimt buffer
N - unsigned char
- the length of data buffer to be transmited.
return value:
I2C_MX_END 4 //Indicate a transmitting has been finished in master model
I2C_TIME_OUT 9 //Indicate I2C overtime.
I2C_NACK 13 //Indicate I2C no acknowledge
I2C_BUSLOST 14 //Indicate I2C bus lost
I2C_BUSY 16 //Indicate I2C bus is busy
-------------------------------------------------------------------------*/
unsigned char upsd_i2c_Master_Xmit (unsigned char Slave_Addr,
unsigned char* Data_Ptr,
unsigned char N);
/*-------------------------------------------------------------------------
unsigned char upsd_i2c_Master_Recv (unsigned char Unit,
unsigned char Slave_Addr,
unsigned char* Data_Ptr,
unsigned char N)
This function is used to receive special length of data from Slave, only for
I2C Master.
Slave_Addr - unsigned char
- Slave address of I2C device.
Data_Ptr - unsigned char*
- address pointer of transimt buffer
N - unsigned char
- the length of data buffer to be transmited.
return value:
I2C_MR_END 8 //Indicate a receiving has been finished in master model
I2C_TIME_OUT 9 //Indicate I2C overtime.
I2C_NACK 13 //Indicate I2C no acknowledge
I2C_BUSLOST 14 //Indicate I2C bus lost
I2C_BUSY 16 //Indicate I2C bus is busy
-------------------------------------------------------------------------*/
unsigned char upsd_i2c_Master_Recv (unsigned char Slave_Addr,
unsigned char* Data_Ptr,
unsigned char N);
/*-------------------------------------------------------------------------
unsigned char upsd_i2c_Slave_Xmit(unsigned char Unit,
unsigned char* Data_Ptr,
unsigned char* N_Ptr)
This function is used to transmit data to master, only for Slave.
Data_Ptr - unsigned char*
- address pointer of transmit buffer
N_Ptr - unsigned char*
- the length of data buffer transmitted to master.
return value:
I2C_SX_END 6 //Indicate a transmitting has been finished in Slave model
I2C_TIME_OUT 9 //Indicate I2C overtime.
I2C_NACK 13 //Indicate I2C no acknowledge
I2C_BUSLOST 14 //Indicate I2C bus lost
I2C_BUSY 16 //Indicate I2C bus is busy
-------------------------------------------------------------------------*/
unsigned char upsd_i2c_Slave_Xmit(unsigned char* Data_Ptr,
unsigned char* N_Ptr);
/*-------------------------------------------------------------------------
unsigned char upsd_i2c_Slave_Recv(unsigned char Unit,
unsigned char* Data_Ptr,
unsigned char* N_Ptr)
This function is used to receive data from master, only for Slave.
Data_Ptr - unsigned char*
- address pointer of receive buffer
N_Ptr - unsigned char*
- the length of data buffer received from master.
return value:
I2C_TIME_OUT 9 //Indicate I2C overtime.
I2C_SR_END 11 //Indicate a receiving has been finished in Slave model
I2C_NACK 13 //Indicate I2C no acknowledge
I2C_BUSLOST 14 //Indicate I2C bus lost
I2C_SX_APP 15 //Indicate I2C Slave is required to transmit data to master
I2C_BUSY 16 //Indicate I2C bus is busy
-------------------------------------------------------------------------*/
unsigned char upsd_i2c_Slave_Recv(unsigned char* Data_Ptr,
unsigned char* N_Ptr);
/*-------------------------------------------------------------------------
The typical value of S1STA and S1CON
-------------------------------------------------------------------------*/
#define GCALL 0x80 // Gen. Call flag
#define STOP 0x40 // Stop cond. flag
#define INTR 0x20 // Interrupt cond flag
#define TX_MODE 0x10 // I2C Tx mode flag
#define BBUSY 0x08 // Bus Busy flag
#define BLOST 0x04 // Bus Lost flag
#define _ACKREP 0x02 // ACK response flag
#define SLV 0x01 // Slave Mode flag
#define CR2 0x80 // Prescaler bit 2
#define ENI 0x40 // Enable I2C
#define STA 0x20 // Start flag
#define STO 0x10 // Stop flag
#define ADDR 0x08 // Indicate that address has been received
#define AA 0x04 // ACK control bit
#define CR1 0x02 // Prescaler bit 1
#define CR0 0x01 // Prescaler bit 0
/*-------------------------------------------------------------------------
Definition of dummy
-------------------------------------------------------------------------*/
#define dummy 0xff // dummy byte to send - needs to be FFH
/*-------------------------------------------------------------------------
The typical value of I2C current state
-------------------------------------------------------------------------*/
#define I2C_MX 3 //Indicate I2C device is transmitting in master model
#define I2C_MX_END 4 //Indicate a transmitting has been finished in master model
#define I2C_SX 5 //Indicate I2C device is transmitting in Slave model
#define I2C_SX_END 6 //Indicate a transmitting has been finished in Slave model
#define I2C_MR 7 //Indicate I2C device is receiving in master model
#define I2C_MR_END 8 //Indicate a receiving has been finished in master model
#define I2C_TIME_OUT 9 //Indicate I2C overtime.
#define I2C_SR 10 //Indicate I2C device is receiving in Slave model
#define I2C_SR_END 11 //Indicate a receiving has been finished in Slave model
#define I2C_NACK 13 //Indicate I2C no acknowledge
#define I2C_BUSLOST 14 //Indicate I2C bus lost
#define I2C_SX_APP 15 //Indicate I2C Slave is required to transmit data to master
#define I2C_BUSY 16 //Indicate I2C bus is busy
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -