Вт июл 31, 2012 11:44:42
#include <avr/io.h>
#include <string.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include "\i2c\deps\i2c.h"
#include "\i2c\deps\UART_routines.h"
#define LOCAL_ADDR 0xA0
#define TARGET_ADDR 0x07
unsigned char buf[100];
unsigned char msgbuf[100];
int main(void)
{
uart0_init();
_delay_ms(1000);
sendStr0("*************TWI MASTER RUNNING*************");
// initialize i2c function library
i2cInit();
// set local device address and allow response to general call
i2cSetLocalDeviceAddr(LOCAL_ADDR, TRUE);
unsigned char mBuf[100];
i2cMasterReceive(TARGET_ADDR, strlen(buf), buf);
sprintf(msgbuf,"master received: %s (length %d)",buf,strlen(buf));
transmitString(msgbuf);
TX_NEWLINE;
#include <avr/io.h>
#include <string.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include "\i2c\deps\i2c.h"
#include "\i2c\deps\UART_routines.h"
#define LOCAL_ADDR 0x07
#define TARGET_ADDR 0xA0
unsigned char buf[40];
unsigned char byteToSend;
// slave operations
void i2cSlaveReceiveService(u08 receiveDataLength, u08* receiveData)
{
sprintf(buf,"slave received: %s (length %d)",receiveData,receiveDataLength);
transmitString(buf);TX_NEWLINE;
}
void i2cSlaveSendService(u08 transmitDataLength, u08 byteToSend)
{
byteToSend=0b00111100;
sprintf(buf,"slave sent: %s (length %d)",byteToSend,transmitDataLength);
transmitString(buf);
TX_NEWLINE;
}
int main(void)
{
uart0_init();
//_delay_ms(10);
sendStr0("*************TWI SLAVE RUNNING*************");
// initialize i2c function library
i2cInit();
// set local device address and allow response to general call
i2cSetLocalDeviceAddr(LOCAL_ADDR, TRUE);
i2cSetSlaveReceiveHandler( i2cSlaveReceiveService );
i2cSetSlaveTransmitHandler(i2cSlaveSendService );
while(1)
{
_delay_ms(100);
}
}
Вт июл 31, 2012 14:32:23
Вт июл 31, 2012 14:50:03
Вт июл 31, 2012 14:53:52
Вт июл 31, 2012 16:22:03
#include <avr/io.h>
#include <string.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include "\i2c\deps\i2c.h"
#include "\i2c\deps\UART_routines.h"
#define LOCAL_ADDR 0xA0
#define TARGET_ADDR 0x07
unsigned char buf[100];
unsigned char msgbuf[100];
int main(void)
{
uart0_init();
_delay_ms(1000);
sendStr0("*************TWI MASTER RUNNING*************");
// initialize i2c function library
i2cInit();
// set local device address and allow response to general call
i2cSetLocalDeviceAddr(LOCAL_ADDR, TRUE);
unsigned char mBuf[100];
// sprintf(mBuf,"%s","hello!");
// mBuf[strlen(mBuf)]=0x00;
//i2cMasterSend(TARGET_ADDR,strlen(mBuf)+1/*(0x00)*/,&mBuf[0]);
char RecBuf[100];
i2cMasterReceive(TARGET_ADDR, strlen(buf), &RecBuf[0]);
//
sprintf(msgbuf,"master received: %s (length %d)",RecBuf,strlen(RecBuf)/*(0x00)*/);
transmitString(msgbuf);
TX_NEWLINE;
Вт июл 31, 2012 16:39:17
SPI debugger
младший разряд запись/чтение (1 чтение )0х07 = 0b00000111
Вт июл 31, 2012 16:46:22
Код:
SPI debugger
а это здесь зачем?? вроде как i2c
Вт июл 31, 2012 16:59:55
Вт июл 31, 2012 17:13:35
Вт июл 31, 2012 18:01:06
void i2cSlaveSendService(u08 transmitDataLength, u08 byteToSend)
{
byteToSend=0b00111100;
sprintf(buf,"slave sent: %s (length %d)",byteToSend,transmitDataLength);
transmitString(buf);
TX_NEWLINE;
}
u08 i2cSlaveSendService(u08 transmitDataLength, u08* byteToSend)
{
*byteToSend=0b00111100;//записать в переменную по указателю byteToSend
// sprintf(buf,"slave sent: %s (length %d)",byteToSend,transmitDataLength);
// transmitString(buf);
// TX_NEWLINE;
return 1; //количество передаваемых байт у тебя один
}
Вт июл 31, 2012 18:27:54
Вт июл 31, 2012 18:31:39
Вт июл 31, 2012 18:47:53
Ср авг 01, 2012 17:08:50
u08 i2cSlaveSendService(u08 transmitDataLength, u08* byteToSend)
{
*byteToSend= 0x11;//записать в переменную по указателю byteToSend
return 1; //количество передаваемых байт у тебя один
}
Ср авг 01, 2012 17:30:13
Ср авг 01, 2012 18:03:09
Ср авг 01, 2012 18:35:42
Ср авг 01, 2012 18:52:24
i2cMasterReceive(TARGET_ADDR, len, RecBuf);
Ср авг 01, 2012 20:08:43
Чт авг 02, 2012 19:40:50