When deciding on a brand new improvement board on your subsequent challenge, one of the vital essential issues to contemplate is the interfaces that it has out there. Can it speak in SPI? How about UART or I2C? It’s by means of these interfaces that the board will talk with exterior gadgets, so if the sensor you need to use doesn’t communicate the identical language as the event board, you’re out of luck.
Nevertheless, in the event you don’t thoughts doing all your challenge in exhausting mode, there’s another choice that ought to all the time be saved in thoughts — bit banging. Similar to it says on the tin, these free GPIO pins are for normal function use, and that features simulating commonplace communications protocols. So long as the GPIO pins can change on and off quick sufficient to maintain up with the specs, there’s nothing stopping you from coding up your personal resolution to copy the sign sample of any current interface.
A few of these interfaces, like UART, will not be too terribly tough to copy. However then there are the robust ones, like Quick Ethernet, which {hardware} hacker Steve Markgraf simply wrote a bit-banging library for. The communication pace is sort of quick, making it difficult for traditional GPIO pins to maintain up with, however Markgraf obtained some assist in that division by utilizing a Raspberry Pi Pico 2. Specialised {hardware} on this board can twiddle the pins at a blazing pace.
Markgraf’s new library, Pico-100BASE-TX, cleverly exploits the Programmable I/O (PIO) subsystem. Utilizing this subsystem, it could actually stream information at roughly 11 MB/s, successfully making a 100 Mbit/s Ethernet transmitter, totally by means of bit banging. However if you wish to obtain indicators as effectively, you’ll have to look elsewhere — the library has not applied that functionality.
Packets acquired from the Pico (📷: Steve Markgraf)
With the pace downside solved, it was time to implement the protocol. 100BASE-TX Ethernet makes use of MLT-3 encoding, which cycles by means of three voltage ranges (-1, 0, +1). It additionally depends on 4B5B encoding and scrambling to take care of sign integrity and stop lengthy runs of similar bits. The scrambler makes use of an 11-bit Linear Suggestions Shift Register, precomputed into lookup tables that take up about 10 KB of RAM. With pre-inverted scrambling and a stream of idle symbols, information will be pushed to the PIO totally by means of DMA, conserving CPU load minimal.
This isn’t totally a plug-and-play Ethernet resolution. Connecting a microcontroller on to a community interface designed for specialised PHY chips is a dangerous transfer. Markgraf warns customers not to hook up with any Energy over Ethernet tools and to make use of both a correct pulse transformer or a resistor community for cover. In testing, he discovered {that a} pair of resistors and an previous Ethernet cable have been typically sufficient, however success diverse relying on the linked {hardware}.
The GitHub repository consists of some instance purposes like counter, which streams a easy 16-bit worth over UDP, internal_adc for sending analog readings, and pcm1802_audio, which transmits 75 kHz audio from an exterior ADC.
Most individuals could be higher off choosing up an Ethernet HAT for his or her Pico, however in case you are in a rush to get your challenge performed and don’t need to look forward to a brand new element to ship, then Pico-100BASE-TX is perhaps simply what you’re on the lookout for.
