00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef _TWI_DRV_H_
00015 #define _TWI_DRV_H_
00016
00017 #define MSK_TWCR_TWINT 0x80
00018 #define MSK_TWCR_TWEA 0x40
00019 #define MSK_TWCR_TWSTA 0x20
00020 #define MSK_TWCR_TWSTO 0x10
00021 #define MSK_TWCR_TWEN 0x04
00022 #define MSK_TWCR_TWIE 0x01
00023
00024
00025 #define Twi_set_address(address) (TWAR = address)
00026 #define Twi_get_address() (TWAR)
00027 #define Twi_set_data(data) (TWDR = data)
00028 #define Twi_set_aa() (TWCR |= MSK_TWCR_TWEA&(~MSK_TWCR_TWINT))
00029 #define Twi_clear_aa() (TWCR &= (~MSK_TWCR_TWEA)&(~MSK_TWCR_TWINT))
00030 #define Twi_get_status() (TWSR)
00031 #define Twi_clear_start() (TWCR &= (~MSK_TWCR_TWSTA)&(~MSK_TWCR_TWINT) )
00032 #define Twi_set_start() (TWCR |= MSK_TWCR_TWSTA)
00033 #define Twi_set_stop() (TWCR |= MSK_TWCR_TWSTO)
00034 #define Twi_clear_stop() (TWCR &= ~MSK_TWCR_TWSTO)
00035 #define Twi_get_data() (TWDR)
00036 #define Twi_clear_si() (TWCR |= MSK_TWCR_TWINT)
00037 #define Twi_set_baudrate(baudrate)(TWBR = baudrate)
00038 #define Twi_wait_hw_stop() while((TWCR & MSK_TWCR_TWSTO)==MSK_TWCR_TWSTO)
00039 #define Twi_wait_event() while(((TWCR & MSK_TWCR_TWINT))!= MSK_TWCR_TWINT)
00040 #define Disable_twi_interrupt() (TWCR &= ~MSK_TWCR_TWIE)
00041 #define Enable_twi_interrupt() (TWCR |= MSK_TWCR_TWIE)
00042 #define Twi_init_hw(arg) (TWCR = arg)
00043
00044
00045 #define Twi_repeated_start() (TWCR |= 0xA4)
00046
00047
00048 #define TWI_BIG_FRAME
00049
00050 #endif