stevemarple / SoftWire

Software I2C implementation for Arduino and other Wiring-type environments
GNU Lesser General Public License v2.1
136 stars 31 forks source link

calling setClock(0) made arduino micro unrecognizable by windows #21

Closed PladsElsker closed 2 years ago

PladsElsker commented 3 years ago

I don't have the source code anymore sadly, and I am kind of scared to repreduce the results on another board. The code was very simple, though. It was something like that:

#include "SoftWire.h"

SoftWire Wire2(4, 5);

void setup()
{
    Wire2.begin();
    Wire2.setClock(0);
}

void loop()
{}

I'm not sure if I called setClock(0) before or after the begin() call.

I'm pretty sure that's what broke it because the parameter 0 in the setClock(0) function is the only value I changed before and after compiling and uploading.

If it's not only my hardware that's at risk, maybe it would be a good idea to prevent users from setting the clock to 0Hz, or to negative numbers (assuming that's even possible).

stevemarple commented 2 years ago

Can you provide any information about what you mean by "broke"? Permanently? It required a power cycle? What board and microcontroller were you using?

PladsElsker commented 2 years ago

This is the board. It's an arduino micro R3.

IMG_20210826_175049.jpg

What I mean by "broken" is that the board is no longer programmable using the arduino software, because the board cannot be recognized by windows.

In my pc's device manager, the board is no logner recognized. I will post a screenshot of this later.

Is it possible to mess with the bootloader using this library? I would be surprised if that was the case, but I'm asking anyway...

Else, do you think this could be related to how the serial communication is handled in the library?

By the way, I don't think I will be using this board again in the future, so it's not really problematic for me. I think it could be for other people, though.

PladsElsker commented 2 years ago

Here is what my device manager looks like:

2021-08-26 18_10_37-

What's more, I can easily program other arduino boards, so the problem is probably not with the instalation of arduino or with the windows drivers on my computer.

stevemarple commented 2 years ago

The bootloader should be protected so that user code cannot mess with it. AVRs have protection for this. If bad user code can mess with the bootloader the error is with fuses not being set correctly.

Since at least 2018-06-02 setClock() has had limits to keep the clock period >= 2 µs and 510 µs (ie clock frequency must be in range 1960 Hz to 500 kHz).

I cannot see how the error is due to the SoftWire library.

PladsElsker commented 2 years ago

Very interesting. The issue must be something else on my side, then. I cannot see how it can be something else, but that's my own problem :p Thanks for the update