Dear Sir/Ma,
Please I need your Support.I am not too sure if this Kind of configuration is possible.I am trying to use the Usi-Spi of Attiny4313(as Master)to receive DATA from Attiny24A(Slave).I am using the GPIO PINs of Attiny24A to send the DATA to the Master.I have already tried this configuration on a breadboard but instead of 4 LEDs ON and 4 LEDs OFF,all my Output Leds were blinking then after sometime all LEDs went OFF except one LED.Below are my lines of code and Pin Configuration.Both Master and Slave are runing @1MHz System clock.
PIN CONFIGURATION
ATTINY4313-------------------ATTINY24A
PB5/DATA_IN-----------------DATA_OUT/PB1
PB6/DATA_OUT----------------DATA_IN/PA1
PB7/USCK--------------------CLK_IN/PA7
Code:
//USI-SPI MASTER CODE
#include <avr/io.h>
#include <avr/delay.h>
//#include <avr/iotn2313.h>
#define CTRL_PORT DDRB
#define DATA_PORT PORTB
#define CLK_PIN PORTB7
#define DI_PIN PORTB5
#define DO_PIN PORTB6
//USI-SPI master
void init()
{
//Configure outputs
CTRL_PORT |= ( 1<<DO_PIN) | (1<< CLK_PIN);
}
unsigned char Transmit(unsigned char data)
{
//Load data
USIDR = data;
//Clear the USI counter overflow flag
USISR = (1<< USIOIF);
do
{
USICR = (1<< USIWM0) | (1<< USICLK) | (1<< USICS1) | (1<< USITC);
} while((USISR & (1<< USIOIF)) == 0);
return USIDR;
}
int main(void)
{
DDRD |= 0xFF; //Led Output
unsigned char dummy_value =20;
init();
while(1)
{
PORTD = Transmit(dummy_value);
}
}
//USI-SPI SLAVE CODE
Code:
#include <avr/io.h>
#include <avr/delay.h>
#include <avr/interrupt.h>
ClearClock()
{
PORTA &= ~(1 << PINA7); // Clear
}
void SetClock()
{
PORTA |= (1 << PINA7); // Set
}
void ToggleClock()
{
SetClock();
ClearClock();
}
void SetData()
{
PORTB |= (1 << PINB1); // Clear
}
void ClearData()
{
PORTB &= ~(1 << PINB1); // Set
}
void send_8Bit(unsigned int data10)
{
int i=7;
do
{
if (((data10 & (1<<i))>>i) == 1)
SetData();
else
ClearData();
ToggleClock();
i=i-1;
}
while (i >= 0);
}
int main(void)
{
unsigned int data;
DDRA |=0b01111111;
DDRB |=(1<<PINB1);
data =0b01010101;
while(1)
{
send_8Bit(data);
}
}
NOTE:The USART and I2C on both Attiny4313 and Attiny24A are already in use.I am using USART on Attiny4313 to send DATA to the PC and the I2C on Attiny24A to read Temperature from a Temperature-Sensor.So I am somehow left with USI-SPI and GPIO PINs for communication between the Master and the slave.Sir I would be very grateful if you could put me through on how to adjust these codes in order to get the desired output
Thank you for the Support.Best regards.
Osanyinpeju.