; I2C (TWI) master interface. ; This is part of the Z80-CP/M emulator written by Sprite_tm. ; ; Copyright (C) 2013 Leo C. ; ; This file is part of avrcpm. ; ; avrcpm is free software: you can redistribute it and/or modify it ; under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; ; avrcpm is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with avrcpm. If not, see . ; ; $Id: i2c.asm 242 2015-12-11 16:05:52Z rapid $ ; #if I2C_SUPPORT /* General TWI Master status codes */ #define TWI_START 0x08 /* START has been transmitted */ #define TWI_REP_START 0x10 /* Repeated START has been transmitted */ #define TWI_ARB_LOST 0x38 /* Arbitration lost */ /* TWI Master Transmitter status codes */ #define TWI_MTX_ADR_ACK 0x18 /* SLA+W has been transmitted and ACK received */ #define TWI_MTX_ADR_NACK 0x20 /* SLA+W has been transmitted and NACK received */ #define TWI_MTX_DATA_ACK 0x28 /* Data byte has been transmitted and ACK received */ #define TWI_MTX_DATA_NACK 0x30 /* Data byte has been transmitted and NACK received */ /* TWI Master Receiver status codes */ #define TWI_MRX_ADR_ACK 0x40 /* SLA+R has been transmitted and ACK received */ #define TWI_MRX_ADR_NACK 0x48 /* SLA+R has been transmitted and NACK received */ #define TWI_MRX_DATA_ACK 0x50 /* Data byte has been received and ACK transmitted */ #define TWI_MRX_DATA_NACK 0x58 /* Data byte has been received and NACK transmitted */ /* TWI Miscellaneous status codes */ #define TWI_NO_STATE 0xF8 /* No relevant state information available */ #define TWI_BUS_ERROR 0x00 /* Bus error due to an illegal START or STOP condition */ #define I2C_BR ((F_CPU / (2 * I2C_CLOCK)) - 8) /* I2C Bit Rate */ ;---------------------------------------------------------------------- ; ; TWINT: TWI Interrupt Flag ; TWEA: TWI Enable Acknowledge Bit ; TWSTA: TWI START Condition Bit ; TWSTO: TWI STOP Condition Bit ; TWEN: TWI Enable Bit ; TWIE: TWI Interrupt Enable ; ; (1< sts i2c_buf,temp ldi temp,(1< std y+oi2c_buf,temp ; Enable TWI, TWI int and initiate start condition ldi temp,(1<