Merge branch 'master' of https://github.com/rogerclarkmelbourne/Arduino_STM32
This commit is contained in:
commit
c05570dbcc
|
@ -347,9 +347,20 @@ void _i2c_irq_handler(i2c_dev *dev) {
|
||||||
* register. We should get another TXE interrupt
|
* register. We should get another TXE interrupt
|
||||||
* immediately to fill DR again.
|
* immediately to fill DR again.
|
||||||
*/
|
*/
|
||||||
if (msg->length != 1) {
|
if (msg->length > 1) {
|
||||||
i2c_write(dev, msg->data[msg->xferred++]);
|
i2c_write(dev, msg->data[msg->xferred++]);
|
||||||
}
|
} else if (msg->length == 0) { /* We're just sending an address */
|
||||||
|
i2c_stop_condition(dev);
|
||||||
|
/*
|
||||||
|
* Turn off event interrupts to keep BTF from firing until
|
||||||
|
* the end of the stop condition. Why on earth they didn't
|
||||||
|
* have a start/stop condition request clear BTF is beyond
|
||||||
|
* me.
|
||||||
|
*/
|
||||||
|
i2c_disable_irq(dev, I2C_IRQ_EVENT);
|
||||||
|
I2C_CRUMB(STOP_SENT, 0, 0);
|
||||||
|
dev->state = I2C_STATE_XFER_DONE;
|
||||||
|
} /* else we're just sending one byte */
|
||||||
}
|
}
|
||||||
sr1 = sr2 = 0;
|
sr1 = sr2 = 0;
|
||||||
}
|
}
|
||||||
|
@ -456,7 +467,7 @@ void _i2c_irq_handler(i2c_dev *dev) {
|
||||||
void _i2c_irq_error_handler(i2c_dev *dev) {
|
void _i2c_irq_error_handler(i2c_dev *dev) {
|
||||||
I2C_CRUMB(ERROR_ENTRY, dev->regs->SR1, dev->regs->SR2);
|
I2C_CRUMB(ERROR_ENTRY, dev->regs->SR1, dev->regs->SR2);
|
||||||
|
|
||||||
dev->error_flags = dev->regs->SR2 & (I2C_SR1_BERR |
|
dev->error_flags = dev->regs->SR1 & (I2C_SR1_BERR |
|
||||||
I2C_SR1_ARLO |
|
I2C_SR1_ARLO |
|
||||||
I2C_SR1_AF |
|
I2C_SR1_AF |
|
||||||
I2C_SR1_OVR);
|
I2C_SR1_OVR);
|
||||||
|
|
|
@ -40,11 +40,19 @@
|
||||||
|
|
||||||
uint8 HardWire::process() {
|
uint8 HardWire::process() {
|
||||||
int8 res = i2c_master_xfer(sel_hard, &itc_msg, 1, 0);
|
int8 res = i2c_master_xfer(sel_hard, &itc_msg, 1, 0);
|
||||||
if (res != 0) {
|
if (res == I2C_ERROR_PROTOCOL) {
|
||||||
|
if (sel_hard->error_flags & I2C_SR1_AF) { /* NACK */
|
||||||
|
res = (sel_hard->error_flags & I2C_SR1_ADDR ? ENACKADDR :
|
||||||
|
ENACKTRNS);
|
||||||
|
} else if (sel_hard->error_flags & I2C_SR1_OVR) { /* Over/Underrun */
|
||||||
|
res = EDATA;
|
||||||
|
} else { /* Bus or Arbitration error */
|
||||||
|
res = EOTHER;
|
||||||
|
}
|
||||||
i2c_disable(sel_hard);
|
i2c_disable(sel_hard);
|
||||||
i2c_master_enable(sel_hard, (I2C_BUS_RESET | dev_flags));
|
i2c_master_enable(sel_hard, (I2C_BUS_RESET | dev_flags));
|
||||||
}
|
}
|
||||||
return 0;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add in Error Handling if devsel is out of range for other Maples
|
// TODO: Add in Error Handling if devsel is out of range for other Maples
|
||||||
|
@ -56,7 +64,7 @@ HardWire::HardWire(uint8 dev_sel, uint8 flags) {
|
||||||
} else {
|
} else {
|
||||||
ASSERT(1);
|
ASSERT(1);
|
||||||
}
|
}
|
||||||
dev_flags=flags;
|
dev_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
HardWire::~HardWire() {
|
HardWire::~HardWire() {
|
||||||
|
|
|
@ -67,5 +67,5 @@ public:
|
||||||
|
|
||||||
void begin(uint8 = 0x00);
|
void begin(uint8 = 0x00);
|
||||||
};
|
};
|
||||||
|
extern HardWire HWire;
|
||||||
#endif // _HARDWIRE_H_
|
#endif // _HARDWIRE_H_
|
||||||
|
|
|
@ -61,11 +61,10 @@ void WireBase::beginTransmission(int slave_address) {
|
||||||
|
|
||||||
uint8 WireBase::endTransmission(void) {
|
uint8 WireBase::endTransmission(void) {
|
||||||
uint8 retVal;
|
uint8 retVal;
|
||||||
|
|
||||||
if (tx_buf_overflow) {
|
if (tx_buf_overflow) {
|
||||||
return EDATA;
|
return EDATA;
|
||||||
}
|
}
|
||||||
retVal=process();// Changed so that the return value from process is returned by this function see also the return line below
|
retVal = process();// Changed so that the return value from process is returned by this function see also the return line below
|
||||||
tx_buf_idx = 0;
|
tx_buf_idx = 0;
|
||||||
tx_buf_overflow = false;
|
tx_buf_overflow = false;
|
||||||
return retVal;//SUCCESS;
|
return retVal;//SUCCESS;
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
// --------------------------------------
|
||||||
|
// i2c_scanner
|
||||||
|
//
|
||||||
|
// Version 1
|
||||||
|
// This program (or code that looks like it)
|
||||||
|
// can be found in many places.
|
||||||
|
// For example on the Arduino.cc forum.
|
||||||
|
// The original author is not know.
|
||||||
|
// Version 2, Juni 2012, Using Arduino 1.0.1
|
||||||
|
// Adapted to be as simple as possible by Arduino.cc user Krodal
|
||||||
|
// Version 3, Feb 26 2013
|
||||||
|
// V3 by louarnold
|
||||||
|
// Version 4, March 3, 2013, Using Arduino 1.0.3
|
||||||
|
// by Arduino.cc user Krodal.
|
||||||
|
// Changes by louarnold removed.
|
||||||
|
// Scanning addresses changed from 0...127 to 1...119,
|
||||||
|
// according to the i2c scanner by Nick Gammon
|
||||||
|
// http://www.gammon.com.au/forum/?id=10896
|
||||||
|
// Version 5, March 28, 2013
|
||||||
|
// As version 4, but address scans now to 127.
|
||||||
|
// A sensor seems to use address 120.
|
||||||
|
// Version 6, August 1, 2015
|
||||||
|
// Modified to support HardWire for STM32duino
|
||||||
|
//
|
||||||
|
// This sketch tests the standard 7-bit addresses
|
||||||
|
// Devices with higher bit address might not be seen properly.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <HardWire.h>
|
||||||
|
|
||||||
|
HardWire HWire(1, I2C_FAST_MODE); // I2c1
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
HWire.begin();
|
||||||
|
Serial.println("\nI2C Scanner");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
byte error, address;
|
||||||
|
int nDevices;
|
||||||
|
|
||||||
|
Serial.println("Scanning...");
|
||||||
|
|
||||||
|
nDevices = 0;
|
||||||
|
for(address = 1; address < 127; address++) {
|
||||||
|
// The i2c_scanner uses the return value of
|
||||||
|
// the Write.endTransmisstion to see if
|
||||||
|
// a device did acknowledge to the address.
|
||||||
|
|
||||||
|
HWire.beginTransmission(address);
|
||||||
|
error = HWire.endTransmission();
|
||||||
|
|
||||||
|
if (error == 0) {
|
||||||
|
Serial.print("I2C device found at address 0x");
|
||||||
|
if (address < 16)
|
||||||
|
Serial.print("0");
|
||||||
|
Serial.println(address, HEX);
|
||||||
|
|
||||||
|
nDevices++;
|
||||||
|
}
|
||||||
|
else if (error == 4) {
|
||||||
|
Serial.print("Unknown error at address 0x");
|
||||||
|
if (address < 16)
|
||||||
|
Serial.print("0");
|
||||||
|
Serial.println(address, HEX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nDevices == 0)
|
||||||
|
Serial.println("No I2C devices found");
|
||||||
|
else
|
||||||
|
Serial.println("done");
|
||||||
|
|
||||||
|
delay(5000); // wait 5 seconds for next scan
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
// --------------------------------------
|
||||||
|
// i2c_scanner
|
||||||
|
//
|
||||||
|
// Version 1
|
||||||
|
// This program (or code that looks like it)
|
||||||
|
// can be found in many places.
|
||||||
|
// For example on the Arduino.cc forum.
|
||||||
|
// The original author is not know.
|
||||||
|
// Version 2, Juni 2012, Using Arduino 1.0.1
|
||||||
|
// Adapted to be as simple as possible by Arduino.cc user Krodal
|
||||||
|
// Version 3, Feb 26 2013
|
||||||
|
// V3 by louarnold
|
||||||
|
// Version 4, March 3, 2013, Using Arduino 1.0.3
|
||||||
|
// by Arduino.cc user Krodal.
|
||||||
|
// Changes by louarnold removed.
|
||||||
|
// Scanning addresses changed from 0...127 to 1...119,
|
||||||
|
// according to the i2c scanner by Nick Gammon
|
||||||
|
// http://www.gammon.com.au/forum/?id=10896
|
||||||
|
// Version 5, March 28, 2013
|
||||||
|
// As version 4, but address scans now to 127.
|
||||||
|
// A sensor seems to use address 120.
|
||||||
|
//
|
||||||
|
// This sketch tests the standard 7-bit addresses
|
||||||
|
// Devices with higher bit address might not be seen properly.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
Serial.begin(115200);
|
||||||
|
Wire.begin();
|
||||||
|
Serial.println("\nI2C Scanner");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
byte error, address;
|
||||||
|
int nDevices;
|
||||||
|
|
||||||
|
Serial.println("Scanning...");
|
||||||
|
|
||||||
|
nDevices = 0;
|
||||||
|
for(address = 1; address < 127; address++) {
|
||||||
|
// The i2c_scanner uses the return value of
|
||||||
|
// the Write.endTransmisstion to see if
|
||||||
|
// a device did acknowledge to the address.
|
||||||
|
|
||||||
|
Wire.beginTransmission(address);
|
||||||
|
error = Wire.endTransmission();
|
||||||
|
|
||||||
|
if (error == 0) {
|
||||||
|
Serial.print("I2C device found at address 0x");
|
||||||
|
if (address < 16)
|
||||||
|
Serial.print("0");
|
||||||
|
Serial.println(address, HEX);
|
||||||
|
|
||||||
|
nDevices++;
|
||||||
|
}
|
||||||
|
else if (error == 4) {
|
||||||
|
Serial.print("Unknown error at address 0x");
|
||||||
|
if (address < 16)
|
||||||
|
Serial.print("0");
|
||||||
|
Serial.println(address, HEX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nDevices == 0)
|
||||||
|
Serial.println("No I2C devices found");
|
||||||
|
else
|
||||||
|
Serial.println("done");
|
||||||
|
|
||||||
|
delay(5000); // wait 5 seconds for next scan
|
||||||
|
}
|
|
@ -33,6 +33,7 @@
|
||||||
#ifndef _WIRISH_H_
|
#ifndef _WIRISH_H_
|
||||||
#define _WIRISH_H_
|
#define _WIRISH_H_
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include "libmaple.h"
|
#include "libmaple.h"
|
||||||
|
|
||||||
#include "wirish_types.h"
|
#include "wirish_types.h"
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue