* ***** Use this API with caution to prevent the I / O direction from changing the input pin into an output pin that causes a short circuit between the output pins and other output pins ***** */ Let's see API definitions.īOOL WINAPI CH341Set_D5_D0( // Set the I / O direction of the D5-D0 pin of CH341 and output data directly through the D5-D0 pin of CH341, which is higher than CH341SetOutput This kind of approach does not allow other SPI modes but we can have up to three distinct slave select pins.
![bluesuite software bluesuite software](https://fasrshanghai745.weebly.com/uploads/1/2/5/7/125778590/966624766.jpg)
D6 and D7 are always inputs and cannot be changed. Before calling it, port needs to be configured using CH341Set_D5_D0 to set data direction and initial state.
![bluesuite software bluesuite software](https://ae01.alicdn.com/kf/HTB18uI_RXXXXXb6aXXXq6xXFXXX0.jpg)
Basically it writes directly to CH341A data port. This function streams data in a bit-banging approach. When streaming an 8-bit byte, clock makes 4 cycles followed by a small pause before next 4 cycles. While clock is low, data defaults to idle state (high), although next bit is low and this shouldn't be necessary. Data is sampled when clock goes low and you can't change this. The read data can be found in the same array that was passed as write buffer. This function performs read and write too. Let's issue this command and check its output. PVOID ioBuffer ) // Point to a buffer, place the data to be written from DOUT, and return the data read from DIN ULONG iLength, // The number of bytes of data to be transferred ULONG iChipSelect, // Chip select control, bit 7 is 0 is ignored chip select control, bit 7 is 1 parameter is valid: bit 1 bit 0 is 00/01/10 select D0 / D1 / D2 pin as low active chip select
#Bluesuite software serial number#
ULONG iIndex, // Specify the CH341 device serial number The DIN / D7 pin is at a high level before the falling edge of the clock enter */ The DOUT / D5 pin is output during the low period before the rising edge of the clock. * SPI Timing: The DCK / D3 pin is clocked and defaults to the low level. Let's see the API definition:īOOL WINAPI CH341StreamSPI4( // Processing the SPI data stream, 4-wire interface, the clock line for the DCK / D3 pin, the output data line DOUT / D5 pin, the input data line for the DIN / D7 pin, chip line for the D0 / D1 / D2, the speed of about 68K bytes It works in the same mode, except a additional I/O buffer that holds data from the second port. I will not talk about CH341StreamSPI5 too. No data is read because there is no slave to send data. I used some 100 ohms resistors because CH341A has 5V levels while the logic analyzer expects 3.3V. I connected my CH341A device to a logic analyzer. The two port mode uses a common clock and common chip select pin, so its usability is somehow limited.ĬH341A MiniProgrammer connected to logic analyzer The chip (slave) select pin can be passed as a parameter to each of these functions. There is one for each port setup (one for single I/O and the other for double port I/O). The API has two main SPI stream functions. Basically, for the MiniProgrammer this is the only bit you have to configure, therefore iMode can be 0x80 or 0x00. If your hardware is MiniProgrammer, D4 and D6 are not connected to anything. D3 remains the common clock source, but D4 and D6 are additional data I/O lines. Setting bit 2 of iMode to 1 enables the second SPI port.
![bluesuite software bluesuite software](https://i.ytimg.com/vi/dQ8wKnZVCQs/maxresdefault.jpg)
#Bluesuite software how to#
Let's see how to use the included library and header to communicate with SPI peripherals. The device can actually be used as USB to SPI converter (not only SPI, but this article will focus only on SPI function). If you got a "MiniProgrammer", you may want to use for more than memory chips programming. And this is probably the cheapest device using CH341A. A popular device is the so-called " CH341A MiniProgrammer" that you can buy for 2 to 5 USD. The IC is somehow limited in this configuration, because the programmer makes use only of the SPI and I2C interface.
![bluesuite software bluesuite software](https://usermanual.wiki/Element/10542B.Operational-Software/User-Guide-812933-Page-4.png)
The chip is manufactured by Chinese company Jiangsu QinHeng Ltd.ĬH341A is used by some cheap memory programmers. Check out the correlation between API functions and bus signal sampled with a logic analyzer.ĬH341A is an USB interface chip that can emulate UART communication, standard parallel port interface, parallel communication and synchronous serial (I2C, SPI). See how to use it to control SPI devices with the C/C++ API. CH341A is the USB interface chip capable of I2C, SPI and serial communication.