Skocz do zawartości

AS3935 problem z komunikacją


user10

Pomocna odpowiedź

Witam. 

chcialbym prosic o pomoc. 

od jakiegoś czasu probuje uruchomic ten czujnik i niestety bez powodzenia. 

czujnik ma 2 interfejsy SPI i I2C. w zaleznosci od podłaczenia pinu SI aktwuje sie jeden z  nich

porzystam z biblioteki https://github.com/PlayingWithFusion/PWFusion_AS3935_I2C

i zgodnie z opisem podlaczam

 

*    Arduino Uno   Arduino Mega  -->  SEN-39001: AS3935 Breakout
*    SDA:    SDA        SDA      -->  MOSI/SDA   (SDA is labeled on the bottom of the Arduino)
*    SCLK:   SCL        SCL      -->  SCK/SCL    (SCL is labeled on the bottom of the Arduino)
*    SI:     pin  9     pin 9    -->  SI (select interface; GND=SPI, VDD=I2C - podlaczam 5V
*    IRQ:    pin  2     pin 2    -->  IRQ
*    GND:    GND        ''       -->  CS (pull CS to ground even though it's not used)
*    GND:    GND        ''       -->  GND
*    5V:     5V         ''       -->  Arduino I/O is at 5V, so power board from 5V. Can use 3.3V with Due, etc

i niestety niedziala. 

program startuje i tak jak by sie wieszal. tzn dochodzi do pierwszego Serial.print wyswietla kilka pierwszych znakow tekstu i nic wiecej sie nie dzieje. 

Ja skanuje magistrale i2c to w zaleznosci od podlaczenia pinów A1 i A0 zmieniaja adresy odpowiednio 0x1, 0x2, 0x3. W kodzie oczywiscie ustawiony odpowiedni

Pelen kod

/***************************************************************************
* File Name: as3935_lightning_i2c_nocal.ino
* Processor/Platform: Arduino Uno R3 (tested)
* Development Environment: Arduino 1.6.1
*
* Designed for use with with Playing With Fusion AS3935 Lightning Sensor
* Breakout: SEN-39001-R01. Demo shows how this lightning sensor can be brought 
* into an Arduino project without a bunch of calibration needed. This is
* because each board is tested calibrated prior to being shipped, and the 
* cal value is written on the packaging.
*
*   SEN-39001-R01 (universal applications)
*   ---> http://www.playingwithfusion.com/productview.php?pdid=22
*
* Copyright © 2015 Playing With Fusion, Inc.
* SOFTWARE LICENSE AGREEMENT: This code is released under the MIT License.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
* **************************************************************************
* REVISION HISTORY:
* Author		Date		Comments
* J. Steinlage		2015Jul20       I2C release based on SPI example
* 
* Playing With Fusion, Inc. invests time and resources developing open-source
* code. Please support Playing With Fusion and continued open-source 
* development by buying products from Playing With Fusion!
*
* **************************************************************************
* APPLICATION SPECIFIC NOTES (READ THIS!!!):
* - This file configures then runs a program on an Arduino to interface with
*   an AS3935 Franklin Lightning Sensor manufactured by AMS.
*    - Configure Arduino
*    - Perform setup for AS3935 chip
*      --- capacitance registers for tuning (based on cal value provided)
*      --- configurations for your application specifics (indoor/outdoor, etc)
*    - read status/info from sensor
*    - Write formatted information to serial port
* - Set configs for your specific needs using the #defines for wiring, and
*   review the setup() function for other settings (indoor/outdoor, for example)
* - I2C specific note: This example uses the I2C interface via the I2C lib, not
*   the 'Wire' lib included with the Arduino IDE.
* 
* Circuit:
*    Arduino Uno   Arduino Mega  -->  SEN-39001: AS3935 Breakout
*    SDA:    SDA        SDA      -->  MOSI/SDA   (SDA is labeled on the bottom of the Arduino)
*    SCLK:   SCL        SCL      -->  SCK/SCL    (SCL is labeled on the bottom of the Arduino)
*    SI:     pin  9     pin 9    -->  SI (select interface; GND=SPI, VDD=I2C
*    IRQ:    pin  2     pin 2    -->  IRQ
*    GND:    GND        ''       -->  CS (pull CS to ground even though it's not used)
*    GND:    GND        ''       -->  GND
*    5V:     5V         ''       -->  Arduino I/O is at 5V, so power board from 5V. Can use 3.3V with Due, etc
**************************************************************************/
// The AS3935 communicates via SPI or I2C. 
// This example uses the I2C interface via the I2C lib, not Wire lib
#include "I2C.h"
// include Playing With Fusion AXS3935 libraries
#include "PWFusion_AS3935_I2C.h"

// interrupt trigger global var        
volatile int8_t AS3935_ISR_Trig = 0;

// defines for hardware config
#define SI_PIN               9
#define IRQ_PIN              2        // digital pins 2 and 3 are available for interrupt capability
#define AS3935_ADD           0x03     // x03 - standard PWF SEN-39001-R01 config
#define AS3935_CAPACITANCE   72       // <-- SET THIS VALUE TO THE NUMBER LISTED ON YOUR BOARD 

// defines for general chip settings
#define AS3935_INDOORS       0
#define AS3935_OUTDOORS      1
#define AS3935_DIST_DIS      0
#define AS3935_DIST_EN       1

// prototypes
void AS3935_ISR();

PWF_AS3935_I2C  lightning0((uint8_t)IRQ_PIN, (uint8_t)SI_PIN, (uint8_t)AS3935_ADD);

void setup()
{
  
  Serial.begin(115200);
  Serial.println("Playing With Fusion: AS3935 Lightning Sensor, SEN-39001-R01");
  Serial.println("beginning boot procedure....");
  
  // setup for the the I2C library: (enable pullups, set speed to 400kHz)
  I2c.begin();
  I2c.pullup(true);
  I2c.setSpeed(1); 
  delay(2);
  
  lightning0.AS3935_DefInit();   // set registers to default  
  // now update sensor cal for your application and power up chip
  lightning0.AS3935_ManualCal(AS3935_CAPACITANCE, AS3935_OUTDOORS, AS3935_DIST_EN);
                                 // AS3935_ManualCal Parameters:
                                 //   --> capacitance, in pF (marked on package)
                                 //   --> indoors/outdoors (AS3935_INDOORS:0 / AS3935_OUTDOORS:1)
                                 //   --> disturbers (AS3935_DIST_EN:1 / AS3935_DIST_DIS:2)
                                 // function also powers up the chip
                  
  // enable interrupt (hook IRQ pin to Arduino Uno/Mega interrupt input: 0 -> pin 2, 1 -> pin 3 )
  attachInterrupt(0, AS3935_ISR, RISING);
  lightning0.AS3935_PrintAllRegs();
  AS3935_ISR_Trig = 0;           // clear trigger

}

void loop()
{
  // This program only handles an AS3935 lightning sensor. It does nothing until 
  // an interrupt is detected on the IRQ pin.
  while(0 == AS3935_ISR_Trig){}
  delay(5);
  
  // reset interrupt flag
  AS3935_ISR_Trig = 0;
  
  // now get interrupt source
  uint8_t int_src = lightning0.AS3935_GetInterruptSrc();
  if(0 == int_src)
  {
    Serial.println("interrupt source result not expected");
  }
  else if(1 == int_src)
  {
    uint8_t lightning_dist_km = lightning0.AS3935_GetLightningDistKm();
    Serial.print("Lightning detected! Distance to strike: ");
    Serial.print(lightning_dist_km);
    Serial.println(" kilometers");
  }
  else if(2 == int_src)
  {
    Serial.println("Disturber detected");
  }
  else if(3 == int_src)
  {
    Serial.println("Noise level too high");
  }
  lightning0.AS3935_PrintAllRegs(); // for debug...
}

// this is irq handler for AS3935 interrupts, has to return void and take no arguments
// always make code in interrupt handlers fast and short
void AS3935_ISR()
{
  AS3935_ISR_Trig = 1;
}

 

Edytowano przez user10
Link do komentarza
Share on other sites

Dnia 29.05.2019 o 10:18, user10 napisał:

dochodzi do pierwszego Serial.print wyswietla kilka pierwszych znakow tekstu i nic wiecej sie nie dzieje.

To wskazuje, że cała początkowa część programu, inicjalizacje zmiennych, odpalenie timera liczenia czasu itp zadania startowe, cały setup() i nawet część loop() wykonują się poprawnie. Objaw o jakim piszesz moim zdaniem może być wywołany jedynie jakimś problemem z przerwaniami zewnętrznymi. Albo podpinasz do złego pinu albo jest tam niepotrzebnie ustawione podciąganie gdy linia jest niepodłączona (to już raczej błąd biblioteki) itp. Wygląda jakby przerwanie było zgłaszane w sposób ciągły lub losowy i to zabija już pracujący system. Spróbuj dla testu odłączyć INT z czujnika (albo cały czujnik) i zewrzeć oba wejścia przerwań (piny 2 i 3) Arduino do masy. Ten scalak swoje przerwania zgłasza stanem wysokim, więc to co zrobisz powinno skutecznie wyłączyć oba wejścia INTx procesora. Jeżeli program zacznie zachowywać się stabilniej (może nie działać obsługa czujnika) to znaczy, że bingo.

EDIT: Teraz jeszcze zauważyłem, że próbujesz odpalić I2C na 400kHz tylko z oporników wbudowanych w porty. To bardzo ryzykownei moim zdaniem nie zadziała. OK, tak jest w przykładzie, ale nie można ślepo powielać głupot. I2C opiera się na pasywnym ładowaniu linii SDA/SCL przez oporniki do stanu wysokiego a nie wiesz jak wyglądał ich zestaw sprzętu. Byćmożeich czujnik był 5cm od płytki Arduino a Twoje kable mają 5m. Albo zależy Ci naprędkości (nie wiem po co) i wtedy dajesz oporniki 4.7-10kΩ od każdej z dwóch linii I2C do Vcc albo zjeżdżasz z prędkością do 20k. Przy naprawdę długich przewodach (>1m), polegane na samych podciągach z procesora jest - niezależnie od prędkości - złym pomysłem. Protokół I2C może utykać na jakimś nieprawidłowym stanie magistrali i zwisać cały program.

Edytowano przez marek1707
Link do komentarza
Share on other sites

Dołącz do dyskusji, napisz odpowiedź!

Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!

Anonim
Dołącz do dyskusji! Kliknij i zacznij pisać...

×   Wklejony jako tekst z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Twoja poprzednia zawartość została przywrócona.   Wyczyść edytor

×   Nie możesz wkleić zdjęć bezpośrednio. Prześlij lub wstaw obrazy z adresu URL.

×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.