Jump to content
ELFORUM - Forumul electronistilor
Gizmo

Date citite de pe o transmisie SPI

Recommended Posts

Am postat prima data pe avrfreaks. Daca cineva ma poate ajuta si nu intelege ceva pentru ca e in engleza, voi traduce. :jytuiyu

 

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

rj4o55.jpg

 

9bm5ah.jpg

 

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)  {   } }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines