Various fixes. Changed stm32.h to remove compile warnings. Changed Wire files to make Wire compile with I2CDev by addition of BUFFER_LENGTH definition, and fixed issue that prevented I2CScanner from working, - by changes in WireBase.cpp, Wire.cpp. Also fixed issue with SCL and SDA pin assignments being the reverse of hardware I2C - to enable future upgrades to Hardware I2C on the same pins, i.e PB6 and PB6 I2C channel 1
This commit is contained in:
parent
bcb767bba9
commit
18d6a286a4
|
@ -36,6 +36,10 @@
|
||||||
* Code was derived from the original Wire for maple code by leaflabs and the
|
* Code was derived from the original Wire for maple code by leaflabs and the
|
||||||
* modifications by gke and ala42.
|
* modifications by gke and ala42.
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
|
* Updated by Roger Clark. 20141111. Fixed issue when process() returned because of missing ACK (often caused by invalid device address being used), caused SCL to be left
|
||||||
|
* LOW so that in the next call to process() , the first clock pulse was not sent, because SCL was LOW when it should have been high.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "Wire.h"
|
#include "Wire.h"
|
||||||
|
|
||||||
|
@ -57,7 +61,7 @@ void TwoWire::set_scl(bool state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwoWire::set_sda(bool state) {
|
void TwoWire::set_sda(bool state) {
|
||||||
I2C_DELAY(this->i2c_delay);
|
I2C_DELAY(this->i2c_delay);
|
||||||
digitalWrite(this->sda_pin, state);
|
digitalWrite(this->sda_pin, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,16 +131,21 @@ uint8 TwoWire::process() {
|
||||||
i2c_start();
|
i2c_start();
|
||||||
// shift out the address we're transmitting to
|
// shift out the address we're transmitting to
|
||||||
i2c_shift_out(sla_addr);
|
i2c_shift_out(sla_addr);
|
||||||
if (!i2c_get_ack()) {
|
if (!i2c_get_ack())
|
||||||
|
{
|
||||||
|
set_scl(HIGH);// Roger Clark. 20141110 added to set clock high again, as it will be left in a low state otherwise
|
||||||
return ENACKADDR;
|
return ENACKADDR;
|
||||||
}
|
}
|
||||||
// Recieving
|
// Recieving
|
||||||
if (itc_msg.flags == I2C_MSG_READ) {
|
if (itc_msg.flags == I2C_MSG_READ) {
|
||||||
while (itc_msg.xferred < itc_msg.length) {
|
while (itc_msg.xferred < itc_msg.length) {
|
||||||
itc_msg.data[itc_msg.xferred++] = i2c_shift_in();
|
itc_msg.data[itc_msg.xferred++] = i2c_shift_in();
|
||||||
if (itc_msg.xferred < itc_msg.length) {
|
if (itc_msg.xferred < itc_msg.length)
|
||||||
|
{
|
||||||
i2c_send_ack();
|
i2c_send_ack();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
i2c_send_nack();
|
i2c_send_nack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +154,9 @@ uint8 TwoWire::process() {
|
||||||
else {
|
else {
|
||||||
for (uint8 i = 0; i < itc_msg.length; i++) {
|
for (uint8 i = 0; i < itc_msg.length; i++) {
|
||||||
i2c_shift_out(itc_msg.data[i]);
|
i2c_shift_out(itc_msg.data[i]);
|
||||||
if (!i2c_get_ack()) {
|
if (!i2c_get_ack())
|
||||||
|
{
|
||||||
|
set_scl(HIGH);// Roger Clark. 20141110 added to set clock high again, as it will be left in a low state otherwise
|
||||||
return ENACKTRNS;
|
return ENACKTRNS;
|
||||||
}
|
}
|
||||||
itc_msg.xferred++;
|
itc_msg.xferred++;
|
||||||
|
@ -180,4 +191,4 @@ TwoWire::~TwoWire() {
|
||||||
|
|
||||||
// Declare the instance that the users of the library can use
|
// Declare the instance that the users of the library can use
|
||||||
//TwoWire Wire(SCL, SDA, SOFT_STANDARD);
|
//TwoWire Wire(SCL, SDA, SOFT_STANDARD);
|
||||||
TwoWire Wire(PB7, PB6, SOFT_FAST);
|
TwoWire Wire(PB6, PB7, SOFT_FAST);
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
//#define I2C_DELAY(x) {uint32 time=micros(); while(time>(micros()+x));}
|
//#define I2C_DELAY(x) {uint32 time=micros(); while(time>(micros()+x));}
|
||||||
#define I2C_DELAY(x) do{for(int i=0;i<x;i++) {asm volatile("nop");}}while(0)
|
#define I2C_DELAY(x) do{for(int i=0;i<x;i++) {asm volatile("nop");}}while(0)
|
||||||
|
|
||||||
|
#define BUFFER_LENGTH 32
|
||||||
|
|
||||||
|
|
||||||
class TwoWire : public WireBase {
|
class TwoWire : public WireBase {
|
||||||
|
|
|
@ -60,13 +60,15 @@ void WireBase::beginTransmission(int slave_address) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 WireBase::endTransmission(void) {
|
uint8 WireBase::endTransmission(void) {
|
||||||
if (tx_buf_overflow) {
|
uint8 retVal;
|
||||||
|
|
||||||
|
if (tx_buf_overflow) {
|
||||||
return EDATA;
|
return EDATA;
|
||||||
}
|
}
|
||||||
process();
|
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 SUCCESS;
|
return retVal;//SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Add the ability to queue messages (adding a boolean to end of function
|
//TODO: Add the ability to queue messages (adding a boolean to end of function
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
* @file libmaple/stm32f1/include/series/stm32.h
|
* @file libmaple/stm32f1/include/series/stm32.h
|
||||||
* @brief STM32F1 chip- and series-specific definitions.
|
* @brief STM32F1 chip- and series-specific definitions.
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
|
* Modified by Roger Clark. 20141111. Wrapped #define STM32_MEDIUM_DENSITY in #ifndef
|
||||||
|
* to prevent redefinition warnings as SSTM32_MEDIUM_DENSITY is defined in boards.txt as a compilor define.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef _LIBMAPLE_STM32F1_H_
|
#ifndef _LIBMAPLE_STM32F1_H_
|
||||||
#define _LIBMAPLE_STM32F1_H_
|
#define _LIBMAPLE_STM32F1_H_
|
||||||
|
@ -68,7 +72,9 @@ extern "C" {
|
||||||
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
|
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
|
||||||
# define STM32_NR_GPIO_PORTS 4
|
# define STM32_NR_GPIO_PORTS 4
|
||||||
# define STM32_SRAM_END ((void*)0x20005000)
|
# define STM32_SRAM_END ((void*)0x20005000)
|
||||||
|
#ifndef STM32_MEDIUM_DENSITY
|
||||||
# define STM32_MEDIUM_DENSITY
|
# define STM32_MEDIUM_DENSITY
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(MCU_STM32F103ZE)
|
#elif defined(MCU_STM32F103ZE)
|
||||||
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
|
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
|
||||||
|
@ -83,13 +89,17 @@ extern "C" {
|
||||||
* so we'll live with this for now. */
|
* so we'll live with this for now. */
|
||||||
# define STM32_NR_GPIO_PORTS 3
|
# define STM32_NR_GPIO_PORTS 3
|
||||||
# define STM32_SRAM_END ((void*)0x20005000)
|
# define STM32_SRAM_END ((void*)0x20005000)
|
||||||
|
#ifndef STM32_MEDIUM_DENSITY
|
||||||
# define STM32_MEDIUM_DENSITY
|
# define STM32_MEDIUM_DENSITY
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(MCU_STM32F103RE)
|
#elif defined(MCU_STM32F103RE)
|
||||||
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
|
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
|
||||||
# define STM32_NR_GPIO_PORTS 4
|
# define STM32_NR_GPIO_PORTS 4
|
||||||
# define STM32_SRAM_END ((void*)0x20010000)
|
# define STM32_SRAM_END ((void*)0x20010000)
|
||||||
# define STM32_HIGH_DENSITY
|
#ifndef STM32_MEDIUM_DENSITY
|
||||||
|
# define STM32_MEDIUM_DENSITY
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(MCU_STM32F100RB)
|
#elif defined(MCU_STM32F100RB)
|
||||||
# define STM32_F1_LINE STM32_F1_LINE_VALUE
|
# define STM32_F1_LINE STM32_F1_LINE_VALUE
|
||||||
|
@ -103,7 +113,9 @@ extern "C" {
|
||||||
# define STM32_SRAM_END ((void*)0x20005000)
|
# define STM32_SRAM_END ((void*)0x20005000)
|
||||||
# define NR_GPIO_PORTS STM32_NR_GPIO_PORTS
|
# define NR_GPIO_PORTS STM32_NR_GPIO_PORTS
|
||||||
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
|
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
|
||||||
|
#ifndef STM32_MEDIUM_DENSITY
|
||||||
# define STM32_MEDIUM_DENSITY
|
# define STM32_MEDIUM_DENSITY
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#warning "Unsupported or unspecified STM32F1 MCU."
|
#warning "Unsupported or unspecified STM32F1 MCU."
|
||||||
|
|
Loading…
Reference in New Issue