Skip to content

Commit bbdc182

Browse files
authored
Correct the transmit protocol for Nordic TWI. (#417)
* Correct the transmit protocol for Nordic TWI. The register address and the data must be sent in one operation, as specified in the nRF51 Series Reference Manual version 3.0. * arch/ARM/Nordic/drivers/nrf_common/nrf-twi.adb: (Master_Transmit): Clear any previous Suspend/Stop settings before the transfer. Only do a Stop_Sequence if requested. (Mem_Write): Call Master_Transmit to send the data as well as the register address in one transaction. This requires moving the Do_Stop_Sequence setting to before this single transaction. * Revert Nordic TWI Mem_Write to original. Avoids creating a potentially large data buffer on the stack. * arch/ARM/Nordic/drivers/nrf_common/nrf-twi.adb (Mem_Write): reverted to sending the register address without a stop sequence, followed by the data, followed by a stop sequence.
1 parent 647eac2 commit bbdc182

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: arch/ARM/Nordic/drivers/nrf_common/nrf-twi.adb

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
------------------------------------------------------------------------------
22
-- --
3-
-- Copyright (C) 2016-2020, AdaCore --
3+
-- Copyright (C) 2016-2022, AdaCore --
44
-- --
55
-- Redistribution and use in source and binary forms, with or without --
66
-- modification, are permitted provided that the following conditions are --
@@ -134,6 +134,11 @@ package body nRF.TWI is
134134
-- Set Address
135135
This.Periph.ADDRESS.ADDRESS := UInt7 (Addr / 2);
136136

137+
-- Configure SHORTS to neither suspend nor stop the TWI port
138+
-- after the next byte transfer.
139+
This.Periph.SHORTS.BB_SUSPEND := Disabled;
140+
This.Periph.SHORTS.BB_STOP := Disabled;
141+
137142
-- Prepare first byte
138143
This.Periph.TXD.TXD := Data (Data'First);
139144

@@ -201,7 +206,6 @@ package body nRF.TWI is
201206
-- Set Address
202207
This.Periph.ADDRESS.ADDRESS := UInt7 (Addr / 2);
203208

204-
205209
if Data'Length = 1 then
206210
-- Only one byte to receive so we stop at the next one
207211
This.Periph.SHORTS.BB_STOP := Enabled;

0 commit comments

Comments
 (0)