Gizmo Postat Iunie 12, 2009 Partajează Postat Iunie 12, 2009 Am postat prima data pe avrfreaks. Daca cineva ma poate ajuta si nu intelege ceva pentru ca e in engleza, voi traduce. I have to read the data from a wireless meteo station: WS1070. There are 6 pins on an RF01 receiver which sends data through SPI protocol to an unknown uC. I have to connect to those pins (MISO, MOSI, CS, CLK) and read data which is transmitted. It transmits clocks of 4, 16 and 24 bits. But only the ones on 24 bit contain data. I hava the C program but I do can not understand where is the problem. The program transmits serial to the PC and it reads from 48 seconds to 48 seconds some data but it is not the one I am looking for and the sequences do not change that much when the data from sensors change. there are 24 clocks Code is written for CEREBOT board. Below the Serial transmision is missing and some initializations. >// FALLING egde detect for INT6#define intCSfalling() EICRB = _BV(ISC61) ; // rising egde detect for INT6#define intCSrising() EICRB = _BV(ISC61) | _BV(ISC60) ; // rising egde detect for INT4#define intCLKrising() EICRB = _BV(ISC41) | _BV(ISC40); volatile int count=0,len=0;volatile char data[50]={0x00};volatile char c;SIGNAL (Sig_CS){//if edge is falling change to rising if (int0==0) { int0 = 1;// reset INT while changing the edge EIMSK &= ~_BV(intCS);intCSrising();EIMSK |= _BV(intCS);//prepare the INT for the next interrupt call EIFR |= _BV(csIntFlag); }// if is rising change to falling else { int0 = 0;// reset INT while changing the edge EIMSK &= ~_BV(intCS);intCSfalling();EIMSK |= _BV(intCS);count = 0;c = 0x00;len = 0;//prepare the INT for the next interrupt callEIFR |= _BV(csIntFlag); }}SIGNAL (Sig_CLK){// if CS is Low //if (int0 == 1) { if (~inPort & _BV(csPin)) { count++; //shift left one position to make place for the comming bit c <<=1; //at each clock, if data is High add a 1 bit at the right if ( (inPort & _BV(dataPin)) ) c |= 0x01; // if a byte is received, add it to the data array, and restart reading // increase the current length of the data vector if (count == 8) { data[len++] = c; c=0x00; count = 0; //if there are 3 bytes (a packet of 24 bits) if (len == 3) { cli(); for (i=0;i USART_Transmit(data[i]); len = 0; sei(); } }} //CS is idle, back to logic 1 else {count = 0;c = 0x00; } //prepare the INT for the next interrupt call EIFR |= _BV(clkIntFlag);}int main(){ // set the pins as inputs dirPort &= ~_BV(dataPin); dirPort &= ~_BV(csPin); dirPort &= ~_BV(clkPin); //activate the interrupts for clk and cs EIMSK |= _BV(intCS) | _BV(intCLK); // Enable Int4 and 6//set CS as falling to catch the first pull low = start condition intCSfalling();// set clk pin as rising edge intCLKrising();// initialize the RS232 interface USART_Init(MYUBRR); int0 = 0; len = 0; c=0x00;// enable all interrupts sei(); while (1) { } } Citează Link spre comentariu Distribuie pe alte site-uri More sharing options...
Postări Recomandate
Alătură-te conversației
Poți posta acum și să te înregistrezi mai târziu. Dacă ai un cont, autentifică-te acum pentru a posta cu contul tău.
Notă: Postarea ta va necesita aprobare moderator înainte de a fi vizibilă.