@@ -1241,6 +1241,9 @@ func (spi SPI) Configure(config SPIConfig) error {
12411241 spi .Bus .CTRLA .ClearBits (sam .SERCOM_SPIM_CTRLA_CPOL )
12421242 }
12431243
1244+ // 32bit
1245+ spi .Bus .CTRLC .SetBits (sam .SERCOM_SPIM_CTRLC_DATA32B )
1246+
12441247 // Set synch speed for SPI
12451248 baudRate := SERCOM_FREQ_REF / (2 * config .Frequency )
12461249 spi .Bus .BAUD .Set (uint8 (baudRate ))
@@ -1256,6 +1259,7 @@ func (spi SPI) Configure(config SPIConfig) error {
12561259// Transfer writes/reads a single byte using the SPI interface.
12571260func (spi SPI ) Transfer (w byte ) (byte , error ) {
12581261 // write data
1262+ spi .Bus .LENGTH .Set (sam .SERCOM_SPIM_LENGTH_LENEN | 1 )
12591263 spi .Bus .DATA .Set (uint32 (w ))
12601264
12611265 // wait for receive
@@ -1266,6 +1270,34 @@ func (spi SPI) Transfer(w byte) (byte, error) {
12661270 return byte (spi .Bus .DATA .Get ()), nil
12671271}
12681272
1273+ // Transfer2 writes/reads a single uint16 using the SPI interface.
1274+ func (spi SPI ) Transfer2 (w uint16 ) (uint16 , error ) {
1275+ // write data
1276+ spi .Bus .LENGTH .Set (sam .SERCOM_SPIM_LENGTH_LENEN | 2 )
1277+ spi .Bus .DATA .Set (uint32 (w ))
1278+
1279+ // wait for receive
1280+ for ! spi .Bus .INTFLAG .HasBits (sam .SERCOM_SPIM_INTFLAG_RXC ) {
1281+ }
1282+
1283+ // return data
1284+ return uint16 (spi .Bus .DATA .Get ()), nil
1285+ }
1286+
1287+ // Transfer4 writes/reads a single uint32 using the SPI interface.
1288+ func (spi SPI ) Transfer4 (w uint32 ) (uint32 , error ) {
1289+ // write data
1290+ spi .Bus .LENGTH .Set (sam .SERCOM_SPIM_LENGTH_LENEN | 4 )
1291+ spi .Bus .DATA .Set (w )
1292+
1293+ // wait for receive
1294+ for ! spi .Bus .INTFLAG .HasBits (sam .SERCOM_SPIM_INTFLAG_RXC ) {
1295+ }
1296+
1297+ // return data
1298+ return spi .Bus .DATA .Get (), nil
1299+ }
1300+
12691301// The QSPI peripheral on ATSAMD51 is only available on the following pins
12701302const (
12711303 QSPI_SCK = PB10
0 commit comments