i just wanted to try to bitbang some bits via GPIO 0 and GPIO 2 but my module resets after every second or so even though i have some delays in my code (i read those are needed to prevent resets). I use the latest esp-open-sdk on Debian 8.6 64-bit. This is the message i get after the reset @115200 Baud
ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x40100000, len 27564, room 16
tail 12
chksum 0x1d
ho 0 tail 12 room 4
load 0x3ffe8000, len 892, room 12
tail 0
chksum 0xc5
load 0x3ffe8380, len 288, room 8
tail 8
chksum 0x09
csum 0x09
and this is my source code:
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#define SCK BIT2
#define SDA BIT0
static volatile os_timer_t timer;
void setHigh(uint32_t GPIO){
gpio_output_set(0,0,0,GPIO);
}
void setLow(uint32_t GPIO){
gpio_output_set(0,GPIO,GPIO,0);
}
void setGPIOs(){
gpio_init();
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);
}
void transferByte(uint8_t byte){
uint8_t bitCycle;
for(bitCycle = 7; bitCycle >= 0; bitCycle++){
uint8_t currentBit = (byte >> bitCycle) & 1;
if(currentBit == 1)
setHigh(SDA);
else
setLow(SDA);
setHigh(SCK);
os_delay_us(3);
setLow(SCK);
}
os_delay_us(10);
}
void ICACHE_FLASH_ATTR user_init()
{
uint8_t byte = 0b10101010;
setGPIOs();
os_timer_setfn(&timer,(os_timer_func_t*)transferByte,byte);
os_timer_arm(&timer,10,1);
}
Any help would be very much appreciated!