You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `Tx` call performs the actual I2C transaction. It first writes the bytes in `w` to the peripheral device indicated in `addr` and then reads `r` bytes from the peripheral and stores the read bytes in the `r` slice. It returns an error if the transaction failed. Both `w` and `r` can be `nil`.
124
+
125
+
126
+
## UART
127
+
128
+
```go
129
+
type UARTConfig struct {
130
+
BaudRate uint32
131
+
TX Pin
132
+
RX Pin
133
+
}
134
+
```
135
+
136
+
The `UARTConfig` struct contains configuration for the UART peripheral.
137
+
138
+
*`BaudRate` is the baud rate of the UART. Common values are 9600 and 115200. Other than that, most chips support multiples of 1200 (2400, 4800, 9600, etc). Support for other baud rates varies by chip, some chips even support high baudrates like 1MHz.
139
+
*`TX` and `RX` are the transmit and receive pins of the UART. Many chips impose restrictions on which pins can be used, some only support a particular TX and RX pin.
140
+
141
+
```go
142
+
typeUARTParityuint8
143
+
144
+
const (
145
+
ParityNoneUARTParity = iota
146
+
ParityEven
147
+
ParityOdd
148
+
)
149
+
```
150
+
151
+
Parity is a rarely used checksum feature of UART.
152
+
153
+
*`ParityNone` is the default, meaning no parity. It is the most commonly used setting.
154
+
*`ParityEven` means to expect that the total number of 1 bits sent should be an even number.
155
+
*`ParityOdd` means to expect that the total number of 1 bits sent should be an odd number.
156
+
157
+
```go
158
+
typeUARTstruct {
159
+
// values are unexported or vary by chip
160
+
}
161
+
162
+
var (
163
+
UART0 = &UART{...}
164
+
UART1 = &UART{...}
165
+
)
166
+
```
167
+
168
+
The `UART` object refers to a single (hardware) UART instance. Depending on chip capabilities, various objects such as `UART0` and perhaps others are defined.
169
+
170
+
```go
171
+
func(uartUART) Configure(configUARTConfig) error
172
+
```
173
+
174
+
The `Configure` call enables and configures the hardware UART for use, setting the pins and baud rate. It will return an error when an incorrect configuration is provided (for example, using pins not usable with this UART instance). See `UARTConfig` for details.
175
+
176
+
Depending on the target configuration, a UART may already be configured if it is the stdout output for the given target. In that case, it is normally configured with a baud rate of 115200.
177
+
178
+
```go
179
+
func (uart *UART) SetBaudRate(br uint32)
180
+
```
181
+
182
+
Set the baud rate for the UART. This method is not available on all chips. See `UARTConfig` above for permissible baud rate values.
Set the UART format. The default format (8N1 meaning 8 bits, no parity, and 1 stop bit) is used for almost all external devices, but if you need it this method can be used to override the default.
189
+
190
+
This method is only available on a limited number of chips.
191
+
192
+
```go
193
+
func (uart *UART) Buffered() int
194
+
```
195
+
196
+
Return the number of bytes stored in the receive buffer.
Read from the receive buffer. This method implements the `io.Reader` interface. It is non-blocking: it will return immediately with `n` set to 0 and `err` set to nil if no data is available.
203
+
204
+
```go
205
+
func (uart *UART) ReadByte() (byte, error)
206
+
```
207
+
208
+
ReadByte reads a single byte from the UART receive buffer. If there is no data available in the buffer, it returns an error. You can use `Buffered` to know whether there is data available.
0 commit comments