Sorry for that, but I’m a little bit out of ideas.
The problem is that I can’t test the hello_world example with the arduino IDE, because my Arduino IDE won’t take my AVR-All programmer.
If recently updated my code and I have a little success. I’m getting the 0x55AA word from Pixy over USART but the rest is senseless.
here the new code and i hope you can help me. My Problem is i’m getting no useful data on the object block, that pixy should send.
The checksum is always invaild.
@/*
- PIXY-CAM.c
-
- Created: 19.01.2015 10:41:07
- Author: jesser
*/
#define F_CPU 16000000UL
#define UARTaktiv //Auskommentieren, um UART zu deaktivieren
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
// #include “Header/Timer.h”
// #include “Header/ADC.h”
// #include “Header/USART.h”
volatile uint8_t y=0;
void TimerInit ()
{
TCCR1A=0b10100001;
TCCR1B=0b00000011;
DDRB=(1<<PINB6) | (1<<PINB5);
}
void USART_init(uint8_t baud)
{
/*Setzen der Baudrate (Übertragungsrate)*/
UBRR1H = (unsigned char) (baud>>8);
UBRR1L = (unsigned char) baud;
/*Aktivieren von Empfänger(RX) und Sender(TX)*/
UCSR1B = (1<<RXEN1) | (1<<TXEN1);
/*Setzen des Formates: 8bit Groß, 2bits zum Stoppen*/
UCSR1C = (1<<USBS1) | (3<<UCSZ10);
}
void USARTTransmit (unsigned char data)
{
/*Auf leeren Übertragungspuffer warten*/
while (!(UCSR1A & (1<<UDRE1)) );
/*Packe die Daten in den Puffer und sende diese*/
UDR1 = data;
}
void USART_Recieve()
{
/*Warte auf Empfangen von Daten*/
while (!(UCSR1A &(1<<RXC1)) );
/*Bekomme die Daten vom Puffe und gebe sie zurück*/
return UDR1;
}
void SPIinit(void)
{
DDRB = (1<<PINB1)|(1<<PINB2)|(1<<PINB0);
SPCR = 0b01110001;
SPSR= 0;
}
unsigned char SPI_start(unsigned char cData)
{
SPDR = cData;
while(!(SPSR & (1<<SPIF)));
return SPDR;
}
uint8_t SensorArray()
{
uint8_t Sensor = 0b00000000;
if (PIND &(1<<4))
Sensor |=(0b00000001);
//if (ADCRead(4) <= 80)
if (PINF &(1<<4))
Sensor |=(0b00000010);
if (PINB &(1<<7))
Sensor |=(0b00000100);
//if (ADCRead(7) <= 80)
if (PINF &(1<<7))
Sensor |=(0b00001000);
//if (ADCRead(5) <= 80)
if (PINF &(1<<5))
Sensor |=(0b00010000);
if(PINC &(1<<6))
Sensor |=(0b00100000);
return Sensor;
}
void PullupSet()
{
PORTB = (1<<PINB7);
PORTC = (1<<PINC6);
PORTD = (1<<PIND4);
PORTF = (1<<PINF7) | (1<<PINF5) | (1<<PINF4);
}
int main(void)
{
uint16_t ObjectBlock;
uint16_t Checksum;
uint16_t signatureNr;
uint16_t xposition;
uint16_t yposition;
uint16_t width;
uint16_t height;
uint16_t count;
uint8_t buffer;
uint8_t sig1;
uint8_t sig2;
TimerInit();
USART_init(103);
PullupSet();
SPIinit();
while(1)
{
count++;
buffer=SPI_start(0xFF);
if(buffer==0xAA )
{
count=0;
sig1 =(buffer);
}
else if (count==1)
sig2 =(buffer);
else if (count==2)
Checksum=buffer;
else if (count==3)
Checksum=Checksum+buffer<<8;
else if (count==4)
signatureNr = buffer;
else if (count==5)
signatureNr+= buffer<<8;
else if (count==6)
xposition=buffer;
else if (count==7)
xposition+=buffer<<8;
else if (count==8)
yposition=buffer;
else if (count==9)
yposition=yposition+buffer<<8;
else if (count==10)
width=buffer;
else if (count==11)
width=width+buffer<<8;
else if (count==12)
height=buffer;
else if (count==13)
height=height+buffer<<8;
if ((sig1==0xAA) && (sig2==0x55))
{
USARTTransmit((uint8_t)((xposition & 0xff00)>>8));
USARTTransmit((uint8_t)(xposition & 0x00ff));
USARTTransmit(sig1);
USARTTransmit(sig2);
USARTTransmit((uint8_t)((Checksum & 0xff00)>>8));
USARTTransmit((uint8_t)(Checksum & 0x00ff));
USARTTransmit((uint8_t)((signatureNr & 0xff00)>>8));
USARTTransmit((uint8_t)(signatureNr & 0x00ff));
USARTTransmit((uint8_t)((xposition & 0xff00)>>8));
USARTTransmit((uint8_t)(xposition & 0x00ff));
USARTTransmit((uint8_t)((yposition & 0xff00)>>8));
USARTTransmit((uint8_t)(yposition & 0x00ff));
USARTTransmit((uint8_t)((width & 0xff00)>>8));
USARTTransmit((uint8_t)(width & 0x00ff));
USARTTransmit((uint8_t)((height & 0xff00)>>8));
USARTTransmit((uint8_t)(height & 0x00ff));
USARTTransmit(13);
}
}
}@