scarmichael
New member
Not sure if this a bug, or PEBCAK... I'm trying to use this library on Teensy 3.1 [https://github.com/jimblom/sha204-Breakout] to communicate with an ATSHA204 [https://www.sparkfun.com/products/11551] that uses a single wire interface. The library uses bitbanging to affect the protocol. For some reason the pin voltages are not being set at all. The lib uses the low level macros digitalPinToPort, portModeRegister, etc. Below is my example sketch, from my understanding, the voltage on pin 12 should be set high then low ad infinitum. When I test the pin with a multimeter I get 0V, and when using the library to try and communicate with the ATSHA204, the SDA pin stays high at a constant voltage of 3.3V. I've looked at this discussion [http://forum.pjrc.com/threads/24116...fnition-confusion?highlight=portModeRegister] and it appears as though although the definition is different, the macros should behave the same, so I can't figure out why no joy.
const int pin = 12;
uint8_t device_pin;
volatile uint8_t *device_port_DDR, *device_port_OUT, *device_port_IN;
void setup() {
// initialize the pin as an swi port.
device_pin = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
device_port_DDR = portModeRegister(port);
device_port_OUT = portOutputRegister(port);
device_port_IN = portInputRegister(port);
}
void loop() {
swi_set_signal_pin(1);
delay(1000); // wait for a second
swi_set_signal_pin(0);
delay(1000); // wait for a second
}
void swi_set_signal_pin(uint8_t is_high)
{
*device_port_DDR |= device_pin;
if (is_high)
*device_port_OUT |= device_pin;
else
*device_port_OUT &= ~device_pin;
}
const int pin = 12;
uint8_t device_pin;
volatile uint8_t *device_port_DDR, *device_port_OUT, *device_port_IN;
void setup() {
// initialize the pin as an swi port.
device_pin = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
device_port_DDR = portModeRegister(port);
device_port_OUT = portOutputRegister(port);
device_port_IN = portInputRegister(port);
}
void loop() {
swi_set_signal_pin(1);
delay(1000); // wait for a second
swi_set_signal_pin(0);
delay(1000); // wait for a second
}
void swi_set_signal_pin(uint8_t is_high)
{
*device_port_DDR |= device_pin;
if (is_high)
*device_port_OUT |= device_pin;
else
*device_port_OUT &= ~device_pin;
}