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:
Roger Clark 2014-11-11 20:10:00 +11:00
parent bcb767bba9
commit 18d6a286a4
4 changed files with 36 additions and 10 deletions

View File

@ -36,6 +36,10 @@
* Code was derived from the original Wire for maple code by leaflabs and the
* 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"
@ -127,16 +131,21 @@ uint8 TwoWire::process() {
i2c_start();
// shift out the address we're transmitting to
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;
}
// Recieving
if (itc_msg.flags == I2C_MSG_READ) {
while (itc_msg.xferred < itc_msg.length) {
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();
} else {
}
else
{
i2c_send_nack();
}
}
@ -145,7 +154,9 @@ uint8 TwoWire::process() {
else {
for (uint8 i = 0; i < itc_msg.length; 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;
}
itc_msg.xferred++;
@ -180,4 +191,4 @@ TwoWire::~TwoWire() {
// Declare the instance that the users of the library can use
//TwoWire Wire(SCL, SDA, SOFT_STANDARD);
TwoWire Wire(PB7, PB6, SOFT_FAST);
TwoWire Wire(PB6, PB7, SOFT_FAST);

View File

@ -57,6 +57,7 @@
//#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 BUFFER_LENGTH 32
class TwoWire : public WireBase {

View File

@ -60,13 +60,15 @@ void WireBase::beginTransmission(int slave_address) {
}
uint8 WireBase::endTransmission(void) {
uint8 retVal;
if (tx_buf_overflow) {
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_overflow = false;
return SUCCESS;
return retVal;//SUCCESS;
}
//TODO: Add the ability to queue messages (adding a boolean to end of function

View File

@ -28,6 +28,10 @@
* @file libmaple/stm32f1/include/series/stm32.h
* @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_
#define _LIBMAPLE_STM32F1_H_
@ -68,7 +72,9 @@ extern "C" {
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
# define STM32_NR_GPIO_PORTS 4
# define STM32_SRAM_END ((void*)0x20005000)
#ifndef STM32_MEDIUM_DENSITY
# define STM32_MEDIUM_DENSITY
#endif
#elif defined(MCU_STM32F103ZE)
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
@ -83,13 +89,17 @@ extern "C" {
* so we'll live with this for now. */
# define STM32_NR_GPIO_PORTS 3
# define STM32_SRAM_END ((void*)0x20005000)
#ifndef STM32_MEDIUM_DENSITY
# define STM32_MEDIUM_DENSITY
#endif
#elif defined(MCU_STM32F103RE)
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
# define STM32_NR_GPIO_PORTS 4
# define STM32_SRAM_END ((void*)0x20010000)
# define STM32_HIGH_DENSITY
#ifndef STM32_MEDIUM_DENSITY
# define STM32_MEDIUM_DENSITY
#endif
#elif defined(MCU_STM32F100RB)
# define STM32_F1_LINE STM32_F1_LINE_VALUE
@ -103,7 +113,9 @@ extern "C" {
# define STM32_SRAM_END ((void*)0x20005000)
# define NR_GPIO_PORTS STM32_NR_GPIO_PORTS
# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
#ifndef STM32_MEDIUM_DENSITY
# define STM32_MEDIUM_DENSITY
#endif
#else
#warning "Unsupported or unspecified STM32F1 MCU."