Subversion Repositories Projects

Rev

Rev 902 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/****************************************************************************
 *   Copyright (C) 2009-2012 by Claas Anders "CaScAdE" Rathje               *
 *   admiralcascade@gmail.com                                               *
 *   Project-URL: http://www.mylifesucks.de/oss/c-strom/                    *
 *                                                                          *
 *   This program 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 2 of the License.         *
 *                                                                          *
 *   This program 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 this program; if not, write to the                          *
 *   Free Software Foundation, Inc.,                                        *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
 ****************************************************************************/



/****************************************************************************
 *                                                                          *
 *  Most of the i²c/twi code is originally from                             *
 *  http://www.rn-wissen.de/index.php/TWI_Slave_mit_avr-gcc                 *
 *                                                                          *
 ****************************************************************************/


#define I2C_BUFFER_SIZE 10

// ACK
#define TWCR_ACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC);  
// NACK
#define TWCR_NACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC);
// non addressed slave mode
#define TWCR_RESET TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC);  


#define CSTROM_I2C 0b00100000 // = 0x20 = 32

volatile uint8_t i2c_rx_buffer[I2C_BUFFER_SIZE];

// here we use the same for SPI and TWI
extern union SPI_buffer_t SPI_buffer;
#define i2c_tx_buffer SPI_buffer.buffer.c

// otherwise take this
//volatile uint8_t i2c_tx_buffer[I2C_BUFFER_SIZE];


volatile uint8_t i2c_buf_adr;


void init_twi_slave (uint8_t);