-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #include // AT91RM9200 definitions
- #include // Library function definitions
- #include "main.h"
- #include "twi.h"
-
-
-
-
-
-
-
-
-
- int AT91F_TWI_Write(const AT91PS_TWI pTwi ,int address, char *data2send, int size)
- {
-
-
- pTwi->TWI_MMR = ( AT91C_EEPROM_I2C_ADDRESS | AT91C_TWI_IADRSZ_2_BYTE ) & ~AT91C_TWI_MREAD;
-
-
- pTwi->TWI_IADR = address;
-
- pTwi->TWI_THR = *(data2send++);
-
- pTwi->TWI_CR = AT91C_TWI_START;
-
- while (size-- >1){
-
-
- while (!(pTwi->TWI_SR & AT91C_TWI_TXRDY));
-
-
- pTwi->TWI_THR = *(data2send++);
-
- }
-
- pTwi->TWI_CR = AT91C_TWI_STOP;
-
-
- while (!(pTwi->TWI_SR & AT91C_TWI_TXCOMP));
-
- return AT91C_EEPROM_WRITE_OK;
- }
-
-
-
-
-
-
-
-
- int AT91F_TWI_Read(const AT91PS_TWI pTwi , int address, char *data, int size)
- {
-
- pTwi->TWI_MMR = AT91C_EEPROM_I2C_ADDRESS | AT91C_TWI_IADRSZ_2_BYTE | AT91C_TWI_MREAD;
-
-
- pTwi->TWI_IADR = address;
-
-
- pTwi->TWI_CR = AT91C_TWI_START;
-
- while (size-- >1){
-
-
- while (!(pTwi->TWI_SR & AT91C_TWI_RXRDY));
-
-
- *(data++) = pTwi->TWI_RHR;
-
- }
-
- pTwi->TWI_CR = AT91C_TWI_STOP;
-
-
- while (!(pTwi->TWI_SR & AT91C_TWI_TXCOMP));
-
-
- *data = pTwi->TWI_RHR;
-
- return AT91C_EEPROM_READ_OK;
- }
//*----------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name : twi.h
//* Object :
//*----------------------------------------------------------------------------
#ifndef twi_h
#define twi_h
#define AT91C_EEPROM_I2C_ADDRESS (0x32<<16)
#define AT91C_EEPROM_READ_OK 0
#define AT91C_EEPROM_WRITE_OK 0
extern int AT91F_TWI_Write (const AT91PS_TWI, int, char *, int );
extern int AT91F_TWI_Read (const AT91PS_TWI, int, char *, int );
#endif
阅读(1424) | 评论(0) | 转发(0) |