View previous topic :: View next topic |
Author |
Message |
CBailey
Joined: 07 May 2015 Posts: 102
|
Posted: Sat Mar 11, 2023 7:54 am Post subject: Unable to get DRV2605L working |
|
|
There's an Adafruit driver for this chip at https://github.com/adafruit/Adafruit_DRV2605_Library
Can this be used with Bascom? If not, has anyone figured this chip out? I've been playing with registers for a while now, so far no output. Not sure if it's my code, a wiring issue, the multiplexer between the microcontroller and the driver, or something else. Hoping to eliminate at least one variable. Thanks! |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Sat Mar 11, 2023 10:28 am Post subject: |
|
|
Maybe you can show us what you have coded so far.
Do you have pull up resistors on the i2c line's?
What cpu are you using? _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
CBailey
Joined: 07 May 2015 Posts: 102
|
Posted: Sat Mar 11, 2023 5:24 pm Post subject: |
|
|
Well, to make things more complicated, I need to drive 8 of these chips. Since they all have the same address, I'm using a TCA9548A. I'm not sure if I'm driving that right either. I didn't add pull up resistors, but my LCD has an I2c adapter on it, and the TCA9548A came on a PCB with some other parts, so I assumed there were pullups in there somewhere. I added code to turn on internal pullups. The LCD is working fine. Below is the code I have. At this point, I'd be happy to set the driver IC to have any kind of output.
' DRV2605L Address is 5A
wait 2 ' This is to give the driver chips a chance to boot up
' We select the correct chip on the TCA9548A
i2cstart
portc.5 = 1
Portc.4 = 1
i2cWByte &H70 ' This is the TCA9548A
i2cWByte &H00 ' This sets output 0 of the TCA9548A
i2cWByte &HB4 ' This writes to the DRV2605L
i2cwbyte &H01 ' This selects register 1
i2cWByte &H00 ' This starts the output
i2cstop
i2cstart
portc.5 = 1
Portc.4 = 1
i2cWByte &H70
i2cWByte &H01
i2cWByte &HB4 ' This writes to the DRV2605L
i2cwbyte &H01 ' This selects register 1
i2cWByte &H00 ' This starts the output
i2cstop
i2cstart
portc.5 = 1
Portc.4 = 1
i2cWByte &H70
i2cWByte &H02
i2cWByte &HB4 ' This writes to the DRV2605L
i2cWByte &H0C ' This starts the output
i2cstop
i2cstart
portc.5 = 1
Portc.4 = 1
i2cWByte &H70
i2cWByte &H03
i2cWByte &H5A ' This writes to the DRV2605L
i2cWByte &H0C ' This starts the output
i2cstop
i2cstart
i2cWByte &H70
i2cWByte &H04
i2cWByte &H5A ' This writes to the DRV2605L
i2cwbyte &H01
i2cWByte &H00 ' This starts the output
i2cstop |
|
Back to top |
|
|
CBailey
Joined: 07 May 2015 Posts: 102
|
Posted: Sat Mar 11, 2023 5:26 pm Post subject: |
|
|
Sorry, using an Arduino Nano, ATMega328 |
|
Back to top |
|
|
CBailey
Joined: 07 May 2015 Posts: 102
|
Posted: Sun Mar 12, 2023 6:35 pm Post subject: |
|
|
I made a little progress. I was writing to the 7 bit address of the TCA9548A. Once I wrote to the 8 bit address, I saw the DRV2605 driver IC (B4) during an I2C scan. I'm still trying to write to the DRV2605, but still no output. This is what I'm currently using:
i2cstart
portc.5 = 1
Portc.4 = 1
i2cWByte &HE0 ' This selects the TCA9548A
i2cWByte &H00 ' This selects the channel of the TCA9548A
i2cWByte &HB4 ' This selects the DRV2605L
i2cwbyte &H01 ' This selects register 1
i2cWByte &H00 ' This starts the output
i2cstop |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sun Mar 12, 2023 10:53 pm Post subject: |
|
|
Hi,
I think you need to split the i2c bus selection and attempting to connect to the slave (DRV2605L) into 2 seperate i2c commends. I've used a Pca9546 on a project and had to program in AVR that way.
Something like :-
Code: |
'Select TCA9548A & Channel
i2cstart
portc.5 = 1
Portc.4 = 1
i2cWByte &HE0 ' This selects the TCA9548A
i2cWByte &H00 ' This selects the channel of the TCA9548A
i2cstop
'Communcate with DRV2605L
i2cstart
i2cWByte &HB4 ' This selects the DRV2605L
i2cwbyte &H01 ' This selects register 1
i2cWByte &H00 ' This starts the output
i2cstop
|
I'm not sure what is on C.5&C.4 so I just left it in the code.
In Bascom i2c addresses are 8 bit, with the lowest bit for Read/Write. Usually in the documentation for i2c chips talk about 7 bit addreses without the lowest bit which defines if the command is a read or write.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
CBailey
Joined: 07 May 2015 Posts: 102
|
Posted: Mon Mar 13, 2023 6:27 am Post subject: |
|
|
Thanks for the help! I think great minds think alike, as I tried splitting them as well. I also realized I was setting the TCA9548A wrong. I was loading it with 0-7 or 1-8 (Wasn't sure), but figured out it's supposed to be binary. It didn't occur to me the chip could connect more than one output at a time. The PortC.4 and PortC.5 are my I2C bus, making pullups.
This is what I have so far. It doesn't work, as I'm not seeing any output from the drivers. I found some C code and translated it to Basic to program one of the chips, but it still didn't make a difference. I'm guessing at this point all the obvious problems are resolved and now it's just about programming the DRV2605L.
i2cstart ' Channel 1
portc.5 = 1
Portc.4 = 1
i2cWByte &HE0 ' This selects the TCA9548A
i2cWByte &H01 ' This selects channel 1 of the TCA9548A
i2cstop
I2CStart
I2CWbyte 0X5A ' // transmit to device #0x5A
I2CWbyte 0x01' // mode register
I2CWbyte 0x07' // Auto calibration Set
I2CStop ' // stop transmitting
I2CStart
I2CWbyte 0x5A' // transmit to device #0x5A a,b,c
I2CWbyte 0x1A' // set ERM_LRA\FB_BRAKE_FACTOR\LOOP_GAIN
I2CWbyte 0xB6' // LRA 4X Medium
I2CStop ' // stop transmitting
I2CStart
I2CWbyte 0x5A' // transmit to device #0x5A d
I2CWbyte 0x16' // Rated voltage set
I2CWbyte 0x53' //
I2CStop ' // stop transmitting
I2CStart
I2CWbyte 0x5A' // transmit to device #0x5A e
I2CWbyte 0x17' // OD_Clamp set
I2CWbyte 0x6E' //
I2CStop' // stop transmitting
I2CStart
I2CWbyte 0x5A' // transmit to device #0x5A f,k
I2CWbyte 0x1E' // Auto_cal_time & Zc_det_time set
I2CWbyte 0xA0' //
I2CStop' // stop transmitting
I2CStart
I2CWbyte 0x5A' // transmit to device #0x5A g
I2CWbyte 0x1B' // Drive_time set
I2CWbyte 0x93' //
I2CStop' // stop transmitting
i2cstart ' Channel 2
portc.5 = 1
Portc.4 = 1
i2cWByte &HE0 ' This selects the TCA9548A
i2cWByte &H02 ' This selects channel 2 of the TCA9548A
i2cstop
i2cstart
i2cWByte &HB4 ' This writes to the DRV2605L
i2cwbyte &H01 ' This selects register 1
i2cWByte &H00 ' This starts the output
i2cstop
i2cstart ' Channel 3
portc.5 = 1
Portc.4 = 1
i2cWByte &HE0 ' This selects the TCA9548A
i2cWByte &H04 ' This selects channel 3 of the TCA9548A
i2cstop
i2cstart
i2cWByte &HB4 ' This writes to the DRV2605L
i2cWByte &H0C ' This starts the output
i2cstop
i2cstart ' Channel 4
portc.5 = 1
Portc.4 = 1
i2cWByte &HE0 ' This selects the TCA9548A
i2cWByte &H08 ' This selects channel 4 of the TCA9548A
i2cstop
i2cstart
i2cWByte &HB4 ' This writes to the DRV2605L
i2cWByte &H0C ' This starts the output
i2cstop
i2cstart ' Channel 5
portc.5 = 1
Portc.4 = 1
i2cWByte &HE0 ' This selects the TCA9548A
i2cWByte &H10 ' This selects channel 5 of the TCA9548A
i2cstop
i2cstart
i2cWByte &HB4 ' This writes to the DRV2605L
i2cwbyte &H01
i2cWByte &H00 ' This starts the output
i2cstop
i2cstart ' Channel 6
portc.5 = 1
Portc.4 = 1
i2cWByte &HE0 ' This selects the TCA9548A
i2cWByte &H20 ' This selects channel 6 of the TCA9548A
i2cstop
i2cstart
i2cWByte &HB4 ' This writes to the DRV2605L
i2cWByte &H02 ' This starts the output
i2cwbyte &H7f
i2cstop
i2cstart ' Channel 7
portc.5 = 1
Portc.4 = 1
i2cWByte &HE0 ' This selects the TCA9548A
i2cWByte &H40 ' This selects channel 7 of the TCA9548A
i2cstop
i2cstart
i2cWByte &HB4 ' This writes to the DRV2605L
i2cWByte &H02 ' This starts the output
i2cwbyte &H7f
i2cstop
i2cstart ' Channel 8
portc.5 = 1
Portc.4 = 1
i2cWByte &HE0 ' This selects the TCA9548A
i2cWByte &H80 ' This selects channel 8 of the TCA9548A
i2cstop
i2cstart
i2cWByte &HB4 ' This writes to the DRV2605L
i2cWByte &H0C ' This starts the output
i2cstop |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Mon Mar 13, 2023 8:49 am Post subject: |
|
|
Hi,
Let first check that the i2c bus between the AVR and the TCA9548A actually works with a simple i2c scanner. I hope you have a working serial port
AVR and the TCA9548A bus only
Code: |
Print , "i2c bus=";
portc.5 = 1
Portc.4 = 1
For Temp_byte = 0 To 254 Step 2 'Scan every even address
I2cstart 'Ping chip
I2cwbyte Temp_byte 'get result
If Err = 0 Then 'err=hw problem
Print , Temp_byte ; "," ; 'no error so device
End If 'ie. no i2c device
I2cstop 'stop bus
Waitms 1
Next Temp_byte 'loop through each sensor
Print ,
|
AVR and the TCA9548A bus 1
Code: |
portc.5 = 1
Portc.4 = 1
Print , "i2c bus=";
i2cstart ' Channel 1
i2cWByte &HE0 ' This selects the TCA9548A
i2cWByte &H01 ' This selects channel 1 of the TCA9548A
i2cstop
For Temp_byte = 0 To 254 Step 2 'Scan every even address
I2cstart 'Ping chip
I2cwbyte Temp_byte 'get result
If Err = 0 Then 'err=hw problem
Print , Temp_byte ; "," ; 'no error so device
End If 'ie. no i2c device
I2cstop 'stop bus
Waitms 1
Next Temp_byte 'loop through each sensor
Print ,
|
As I said I've used a Pca9546, here's the function I'm using to select the bus.
Code: |
Const Pca9546_w = 224
Const Pca9546_r = 225
Const I2c_bus_none = &B0000
Const I2c_bus_zero = &B0001
Const I2c_bus_one = &B0010
Const I2c_bus_two = &B0100
Const I2c_bus_three = &B1000
Const I2c_bus_all = &B1111
Const I2c_bus_used = &B0101
call Select_bus(I2c_bus_zero)
end
Sub Select_bus(byval Bus As Byte)
Temp_byte = Bus
I2cstart
I2cwbyte Pca9546_w
I2cwbyte Temp_byte
I2cstop
End Sub
|
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Mon Mar 13, 2023 8:55 am Post subject: |
|
|
Hi,
I would recommend that you use external pullups for all i2c buses, rather than trying to use the AVR's internal pullups.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
|