Subversion Repositories Projects

Rev

Rev 902 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
771 - 1
/****************************************************************************
1437 - 2
 *   Copyright (C) 2009-2012 by Claas Anders "CaScAdE" Rathje               *
771 - 3
 *   admiralcascade@gmail.com                                               *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-strom/                    *
5
 *                                                                          *
6
 *   This program is free software; you can redistribute it and/or modify   *
7
 *   it under the terms of the GNU General Public License as published by   *
8
 *   the Free Software Foundation; either version 2 of the License.         *
9
 *                                                                          *
10
 *   This program is distributed in the hope that it will be useful,        *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
13
 *   GNU General Public License for more details.                           *
14
 *                                                                          *
15
 *   You should have received a copy of the GNU General Public License      *
16
 *   along with this program; if not, write to the                          *
17
 *   Free Software Foundation, Inc.,                                        *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
19
 ****************************************************************************/
20
 
21
 
22
/****************************************************************************
23
 *                                                                          *
24
 *  Most of the ic/twi code is originally from                             *
25
 *  http://www.rn-wissen.de/index.php/TWI_Slave_mit_avr-gcc                 *
26
 *                                                                          *
27
 ****************************************************************************/
28
 
29
#define I2C_BUFFER_SIZE 10
30
 
31
// ACK 
32
#define TWCR_ACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC);  
33
// NACK 
34
#define TWCR_NACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC);
35
// non addressed slave mode
36
#define TWCR_RESET TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC);  
37
 
38
 
39
#define CSTROM_I2C 0b00100000 // = 0x20 = 32
40
 
41
volatile uint8_t i2c_rx_buffer[I2C_BUFFER_SIZE];
42
 
43
// here we use the same for SPI and TWI
44
extern union SPI_buffer_t SPI_buffer;
45
#define i2c_tx_buffer SPI_buffer.buffer.c
46
 
47
// otherwise take this
48
//volatile uint8_t i2c_tx_buffer[I2C_BUFFER_SIZE];
49
 
50
 
51
volatile uint8_t i2c_buf_adr;
52
 
53
 
54
void init_twi_slave (uint8_t);