@@ -204,15 +204,26 @@ internal static void ConfigureDeserializer(DeviceContext device)
204204 i2cAlias = UclaMiniscopeV4 . Max14574Address << 1 ;
205205 deserializer . WriteByte ( ( uint ) DS90UB9xDeserializerI2CRegister . SlaveID3 , i2cAlias ) ;
206206 deserializer . WriteByte ( ( uint ) DS90UB9xDeserializerI2CRegister . SlaveAlias3 , i2cAlias ) ;
207+
208+ // Nominal I2C rate for miniscope
209+ Set200kHzI2C ( device ) ;
210+ }
211+
212+ static void Set80kHzI2C ( DeviceContext device )
213+ {
214+ DS90UB9x . Set933I2CRate ( device , 80e3 ) ; // Empirical data for reliably communication with atMega
207215 }
208216
209- internal static void ConfigureSerializer ( DeviceContext device )
217+ static void Set200kHzI2C ( DeviceContext device )
210218 {
211- DS90UB9x . Set933I2CRate ( device , 80e3 ) ; //This is an arbitrary value that is proven to work, we need to test speed vs reliability vs bno sampling speed
219+ DS90UB9x . Set933I2CRate ( device , 200e3 ) ; // This allows maximum rate bno sampling
212220 }
213221
214222 internal static void ConfigureCameraSystem ( DeviceContext device , UclaMiniscopeV4FramesPerSecond frameRate , bool interleaveLed )
215223 {
224+ // NB: atMega (bit-banded i2c to SPI) requires that we talk slowly
225+ Set80kHzI2C ( device ) ;
226+
216227 // set up Python480
217228 var atMega = new I2CRegisterContext ( device , UclaMiniscopeV4 . AtMegaAddress ) ;
218229 WriteCameraRegister ( atMega , 16 , 3 ) ; // Turn on PLL
@@ -243,6 +254,10 @@ internal static void ConfigureCameraSystem(DeviceContext device, UclaMiniscopeV4
243254
244255 atMega . WriteByte ( 0x04 , ( uint ) ( interleaveLed ? 0x00 : 0x03 ) ) ;
245256 WriteCameraRegister ( atMega , 200 , shutterWidth ) ;
257+
258+ // NB: interaction with the atMega (bit-banded i2c to SPI) requires that we talk slowly, reset to
259+ // talk to normal chips
260+ Set200kHzI2C ( device ) ;
246261 }
247262
248263 static void WriteCameraRegister ( I2CRegisterContext i2c , uint register , uint value )
@@ -260,17 +275,23 @@ static void WriteCameraRegister(I2CRegisterContext i2c, uint register, uint valu
260275
261276 internal static void SetLedBrightness ( DeviceContext device , double percent )
262277 {
278+ // NB: atMega (bit-banded i2c to SPI) requires that we talk slowly
279+ Set80kHzI2C ( device ) ;
263280 var atMega = new I2CRegisterContext ( device , UclaMiniscopeV4 . AtMegaAddress ) ;
264281 atMega . WriteByte ( 0x01 , ( uint ) ( ( percent == 0 ) ? 0xFF : 0x08 ) ) ;
265282
266283 var tpl0102 = new I2CRegisterContext ( device , UclaMiniscopeV4 . Tpl0102Address ) ;
267284 tpl0102 . WriteByte ( 0x01 , ( uint ) ( 255 * ( ( 100 - percent ) / 100.0 ) ) ) ;
285+ Set200kHzI2C ( device ) ;
268286 }
269287
270288 internal static void SetSensorGain ( DeviceContext device , UclaMiniscopeV4SensorGain gain )
271289 {
290+ // NB: atMega (bit-banded i2c to SPI) requires that we talk slowly
291+ Set80kHzI2C ( device ) ;
272292 var atMega = new I2CRegisterContext ( device , UclaMiniscopeV4 . AtMegaAddress ) ;
273293 WriteCameraRegister ( atMega , 204 , ( uint ) gain ) ;
294+ Set200kHzI2C ( device ) ;
274295 }
275296
276297 internal static void SetLiquidLensVoltage ( DeviceContext device , double voltage )
0 commit comments