115200 is pretty close, about every 6 char's are off by a bit or so but 74880 seems completely off.
Someone want to give it a shot and report back to see how high they could go?
Code: Select all
static inline u8 chbit(u8 data, u8 bit)
{
if ((data & bit) != 0)
{
return 1;
}
else
{
return 0;
}
}
#define DIRECT_WRITE(v) (GPIO_OUTPUT_SET(GPIO_ID_PIN(1), v))
//#define DIRECT_WRITE(v) (GPIO_OUTPUT_SET(GPIO_ID_PIN(2), v))
static int soft_uart_putchar_c(unsigned bit_time, char data)
{
unsigned i;
unsigned start_time = 0x7FFFFFFF & system_get_time();
//Start Bit
DIRECT_WRITE(0);
for(i = 0; i <= 8; i ++ )
{
while ((0x7FFFFFFF & system_get_time()) < (start_time + (bit_time*(i+1))))
{
//If system timer overflow, escape from while loop
if ((0x7FFFFFFF & system_get_time()) < start_time){break;}
}
DIRECT_WRITE(chbit(data,1<<i));
}
// Stop bit
while ((0x7FFFFFFF & system_get_time()) < (start_time + (bit_time*9)))
{
//If system timer overflow, escape from while loop
if ((0x7FFFFFFF & system_get_time()) < start_time){break;}
}
DIRECT_WRITE(1);
// Delay after byte, for new sync
os_delay_us(bit_time*6);
return 1;
}
int softuart_write( const char* data, unsigned len )
{
const unsigned baudrate = 74880;
const unsigned bit_time = (1000000 / baudrate);
DIRECT_WRITE(1);
os_delay_us(bit_time*8);
int s=0;
for(; s < len; ++s )
{
soft_uart_putchar_c(bit_time, data[ s ]);
}
return 0;
}
void ICACHE_FLASH_ATTR sdk_init_done_cb(void)
{
os_printf("[%s] initializing ESP8266!\n", __func__);
while(true)
{
//os_printf("rrrr");
//sendUART(2, "rrrr", 4, 115200);
softuart_write("This is a test\r\n", 17);
delay_second();
//delay_second();
}
}
void ICACHE_FLASH_ATTR user_init()
{
uart_div_modify(0, UART_CLK_FREQ / 115200);
system_uart_swap();
//system_uart_de_swap();
system_init_done_cb(sdk_init_done_cb);
wifi_set_opmode(0);
wifi_set_sleep_type( NONE_SLEEP_T );
ETS_GPIO_INTR_DISABLE();// Disable gpio interrupts
gpio_init();
SetAllGPIOPinsAsOutput();
/* Need to fix this to display value */
uint32 VDDADCByte[4] = {0};
spi_flash_read(0x3fc06b, (uint32 *)&VDDADCByte, 1); //Read pads the other 3 bytes with FF
os_printf("\r\n\r\nStarting ESP8266 OTA!\r\nSDK version:%s\r\nLoaded from: %02x\r\nVdd33_Const: %02x\r\n", system_get_sdk_version(), system_get_userbin_addr(), (VDDADCByte[0] & 0xff));
//Turn off LED, We cannot touch this pin as this is our debug pin D4/GPIO2
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1);
gpio_output_set((1 << 1), 0, (1 << 1), 0);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
gpio_output_set((1 << 2), 0, (1 << 2), 0);
//Start os task
system_init_done_cb(sdk_init_done_cb);
//system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); //Task to Signal for later
}