DRV8912 mit Pi4J über SPI ansteuern

OP #8040441
Lesenswert?

Hallo,

ich versuche einen DRV8912 mit einem Raspberry Pi 3 über SPI anzusteuern. Allerdings leugnet der DRV8912 alle Befehle in jeglicher Form die ich ihm schicke. Wenn ich auf PWM_FREQ_CTRL 0xAA setze und dann zurück lese kommt nur 0x00 zurück. Byte order vertauschen, SPI Mode 0 oder 1, Frequenz erhöhen oder senken bringt alles nichts. Teilweise kommen gelogene Fehler in den Registern zurück, dass irgendwo overcurrent protection angesprochen hat wo nicht mal ein Motor angeschlossen ist. Deswegen versuche ich auch sämtliche dieser Erkennungen abzuschalten. Beide Chips treiben irgendwas und ignorieren alles was auf dem SPI Bus daher kommt. Der FAULT Ausgang beider DRV9012 wird als LOW erkannt bei 3.8V. Eine vernünftige Spannung (0V oder 5V) liegt niemals an. Versorgungsspannung ist 5V und Motorspannung 20.5V.

1
public final class MotorController {
2
    private static final int IC_STAT = 0x00;
3
    private static final int OCP_STAT_1 = 0x01;
4
    private static final int OCP_STAT_2 = 0x02;
5
    private static final int OCP_STAT_3 = 0x03;
6
    private static final int OLD_STAT_1 = 0x04;
7
    private static final int OLD_STAT_2 = 0x05;
8
    private static final int OLD_STAT_3 = 0x06;
9

10
    private static final int CONFIG_CTRL = 0x07;
11
    private static final int OP_CTRL_1 = 0x08;
12
    private static final int OP_CTRL_2 = 0x09;
13
    private static final int OP_CTRL_3 = 0x0A;
14
    private static final int PWM_CTRL_1 = 0x0B;
15
    private static final int PWM_CTRL_2 = 0x0C;
16
    private static final int FW_CTRL_1 = 0x0D;
17
    private static final int FW_CTRL_2 = 0x0E;
18
    private static final int PWM_MAP_CTRL_1 = 0x0F;
19
    private static final int PWM_MAP_CTRL_2 = 0x10;
20
    private static final int PWM_MAP_CTRL_3 = 0x11;
21
    private static final int PWM_FREQ_CTRL = 0x12;
22
    private static final int PWM_DUTY_CTRL_1 = 0x13;
23
    private static final int PWM_DUTY_CTRL_2 = 0x14;
24
    private static final int PWM_DUTY_CTRL_3 = 0x15;
25
    private static final int PWM_DUTY_CTRL_4 = 0x16;
26
    private static final int SR_CTRL_1 = 0x17;
27
    private static final int SR_CTRL_2 = 0x18;
28
    private static final int OLD_CTRL_1 = 0x19;
29
    private static final int OLD_CTRL_2 = 0x1A;
30
    private static final int OLD_CTRL_3 = 0x1B;
31
    private static final int OLD_CTRL_4 = 0x24;
32

33
    private final Spi drv0, drv1;
34
    private final DigitalInput fault1, fault2;
35

36
    public MotorController(Context pi4j) {
37
        fault1 = pi4j.create(DigitalInput.newConfigBuilder(pi4j).address(24).pull(PullResistance.PULL_UP));
38
        fault2 = pi4j.create(DigitalInput.newConfigBuilder(pi4j).address(25).pull(PullResistance.PULL_UP));
39

40
        final int spiClockFreq = 1_000_000; // Hz
41
        final SpiMode mode = SpiMode.MODE_1;
42
        drv0 = pi4j.create(Spi.newConfigBuilder(pi4j).bus(SpiBus.BUS_0).chipSelect(SpiChipSelect.CS_0).mode(mode).baud(spiClockFreq));
43
        drv1 = pi4j.create(Spi.newConfigBuilder(pi4j).bus(SpiBus.BUS_0).chipSelect(SpiChipSelect.CS_1).mode(mode).baud(spiClockFreq));
44

45
        initializeChip(drv0);
46
        initializeChip(drv1);
47
    }
48

49
    private void initializeChip(Spi spi) {
50
        write(spi, OP_CTRL_1, (byte) 0x00);
51
        write(spi, OP_CTRL_2, (byte) 0x00);
52
        write(spi, OP_CTRL_3, (byte) 0x00);
53

54
        write(spi, OLD_CTRL_1, (byte) 0x00);
55
        write(spi, OLD_CTRL_2, (byte) 0x00);
56
        write(spi, OLD_CTRL_3, (byte) 0x00);
57
        write(spi, OLD_CTRL_4, (byte) 0x00);
58

59
        write(spi, CONFIG_CTRL, (byte) 0x81);
60

61
        write(spi, PWM_FREQ_CTRL, (byte) 0xAA); // 20kHz
62
        write(spi, SR_CTRL_1, (byte) 0x00);
63
        write(spi, SR_CTRL_2, (byte) 0x00);
64

65
        write(spi, CONFIG_CTRL, (byte) 0x81);
66

67
        System.out.print("PWM_FREQ_CTRL: ");
68
        printBytes(read(spi, PWM_FREQ_CTRL));
69
    }
70

71
    private byte write(Spi spi, int registerAddress, byte value) {
72
        byte command = (byte) (64 | (registerAddress & 0x3F));
73
        byte[] readBuffer = new byte[2];
74
        spi.transfer(new byte[] { command, value }, readBuffer);
75
        return readBuffer[1];
76
    }
77

78
    private byte read(Spi spi, int registerAddress) {
79
        return write(spi, registerAddress, (byte) 0);
80
    }
81
}

Hat jemand schon mal versucht diese Chips zum Laufen zu bekommen? Ist evtl. Pi4J verbuggt (CS bleibt nicht low bei mehreren Bytes, ...)?

Angehängte Dateien:
: Verschoben durch Moderator
#8040499
Lesenswert?

Schon mal einen Logic Analyzer abgeschlossen und versucht ein Register zu lesen/schreiben? Sieht das ganze dann aus wie im Datenblatt des DRV8912?

Ich hätte ja gesagt Versuche erst Mal die Chip ID oder so aus zu lesen. Aber ich glaube da steht in deinem Fall eine 0 drauf. Bringt also nichts.

: Bearbeitet durch User

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren