DRV10983驱动无刷电机调试过程与踩坑记录

因为工作需要,目前在验证DRV10983这块驱动芯片是否能满足我们驱动无刷电机的需求。不出意料踩了坑,看了看官网论坛也有类似的问题,索性分享出来让大家少走点弯路。

 

1.问题描述

首先,我们来看看它的数据手册

看到可以直接通过PWM或者I2C输入控制电机,于是硬件交给我板子的时候说,“你接个PWM应该就能动了。”然后我输出了一路PWM波,接上去,它抖了一下,动了,转了。

然后10秒以后就停了。

咋回事啊?

2.原因分析

翻查数据手册,对比了一下,我输出的这路PWM波高低电平和频率都符合要求,输入的电压也没有问题。那么问题应该是在芯片这里了。或许应该使用i2c来写速度?

于是接了SDA和SCL出来连I2C,在正常通讯以后,也读到了相关的配置。

msh />pcf8574_sample 2 0 0
[38561] D/I2C: I2C bus dev [i2c1] writing 1 bytes.
[38566] D/I2C: msgs[0] W, addr=0x52, len=1
[38570] D/I2C: send start condition
[38574] D/I2C: ACK
[38576] D/I2C: ACK
[38578] D/I2C: write 1 byte
[38581] D/I2C: send stop condition
[38584] D/I2C: msgs[0] W, addr=0x52, len=2
[38589] D/I2C: send start condition
[38592] D/I2C: ACK
[38595] D/I2C: ACK
[38597] D/I2C: ACK
[38599] D/I2C: write 2 bytes
[38602] D/I2C: send stop condition
Success
[38606] D/I2C: msgs[0] W, addr=0x52, len=2
[38610] D/I2C: send start condition
[38614] D/I2C: ACK
[38616] D/I2C: ACK
[38618] D/I2C: ACK
[38621] D/I2C: write 2 bytes
[38623] D/I2C: send stop condition
Success
[38628] D/I2C: msgs[0] W, addr=0x52, len=2
[38632] D/I2C: send start condition
[38636] D/I2C: ACK
[38638] D/I2C: ACK
[38640] D/I2C: ACK
[38642] D/I2C: write 2 bytes
[38645] D/I2C: send stop condition
Success
[38650] D/I2C: msgs[0] W, addr=0x52, len=2
[38654] D/I2C: send start condition
[38658] D/I2C: ACK
[38660] D/I2C: ACK
[38662] D/I2C: ACK
[38664] D/I2C: write 2 bytes
[38667] D/I2C: send stop condition
Success
[38671] D/I2C: msgs[0] W, addr=0x52, len=2
[38676] D/I2C: send start condition
[38679] D/I2C: ACK
[38682] D/I2C: ACK
[38684] D/I2C: ACK
[38686] D/I2C: write 2 bytes
[38689] D/I2C: send stop condition
Success
[38693] D/I2C: msgs[0] W, addr=0x52, len=2
[38697] D/I2C: send start condition
[38701] D/I2C: ACK
[38703] D/I2C: ACK
[38705] D/I2C: ACK
[38708] D/I2C: write 2 bytes
[38710] D/I2C: send stop condition
Success
[38715] D/I2C: msgs[0] W, addr=0x52, len=1
[38719] D/I2C: msgs[1] R, addr=0x52, len=2
[38724] D/I2C: send start condition
[38727] D/I2C: ACK
[38729] D/I2C: ACK
[38731] D/I2C: write 1 byte
[38734] D/I2C: ACK
[38737] D/I2C: recieve bytes: 0x40, ACK
[38741] D/I2C: recieve bytes: 0xff, NACK
[38745] D/I2C: read 2 bytes
[38748] D/I2C: send stop condition
Success
data 0x03 :40 ff
[38754] D/I2C: msgs[0] W, addr=0x52, len=1
[38758] D/I2C: msgs[1] R, addr=0x52, len=2
[38763] D/I2C: send start condition
[38766] D/I2C: ACK
[38768] D/I2C: ACK
[38770] D/I2C: write 1 byte
[38773] D/I2C: ACK
[38776] D/I2C: recieve bytes: 0x80, ACK
[38780] D/I2C: recieve bytes: 0xff, NACK
[38784] D/I2C: read 2 bytes
[38787] D/I2C: send stop condition
Success
data 0x01 :80 ff
[38793] D/I2C: msgs[0] W, addr=0x52, len=1
[38797] D/I2C: msgs[1] R, addr=0x52, len=2
[38801] D/I2C: send start condition
[38805] D/I2C: ACK
[38807] D/I2C: ACK
[38809] D/I2C: write 1 byte
[38812] D/I2C: ACK
[38814] D/I2C: recieve bytes: 0x80, ACK
[38819] D/I2C: recieve bytes: 0xff, NACK
[38823] D/I2C: read 2 bytes
[38826] D/I2C: send stop condition
Success
data 0x00 :80 ff
[38832] D/I2C: msgs[0] W, addr=0x52, len=1
[38836] D/I2C: msgs[1] R, addr=0x52, len=2
[38840] D/I2C: send start condition
[38844] D/I2C: ACK
[38846] D/I2C: ACK
[38848] D/I2C: write 1 byte
[38851] D/I2C: ACK
[38853] D/I2C: recieve bytes: 0x40, ACK
[38858] D/I2C: recieve bytes: 0xff, NACK
[38862] D/I2C: read 2 bytes
[38865] D/I2C: send stop condition
Success
data 0x1b :40 ff
[38871] D/I2C: msgs[0] W, addr=0x52, len=1
[38875] D/I2C: msgs[1] R, addr=0x52, len=2
[38879] D/I2C: send start condition
[38883] D/I2C: ACK
[38885] D/I2C: ACK
[38887] D/I2C: write 1 byte
[38890] D/I2C: ACK
[38892] D/I2C: recieve bytes: 0x3f, ACK
[38897] D/I2C: recieve bytes: 0xff, NACK
[38901] D/I2C: read 2 bytes
[38904] D/I2C: send stop condition
Success
data 0x11 :3f ff
[38910] D/I2C: msgs[0] W, addr=0x52, len=1
[38914] D/I2C: msgs[1] R, addr=0x52, len=2
[38918] D/I2C: send start condition
[38922] D/I2C: ACK
[38924] D/I2C: ACK
[38926] D/I2C: write 1 byte
[38929] D/I2C: ACK
[38931] D/I2C: recieve bytes: 0xff, ACK
[38935] D/I2C: recieve bytes: 0xff, NACK
[38940] D/I2C: read 2 bytes
[38943] D/I2C: send stop condition
Success
data 0x12 :ff ff
[38949] D/I2C: msgs[0] W, addr=0x52, len=1
[38953] D/I2C: msgs[1] R, addr=0x52, len=2
[38957] D/I2C: send start condition
[38961] D/I2C: ACK
[38963] D/I2C: ACK
[38965] D/I2C: write 1 byte
[38968] D/I2C: ACK
[38970] D/I2C: recieve bytes: 0x4e, ACK
[38974] D/I2C: recieve bytes: 0xff, NACK
[38979] D/I2C: read 2 bytes
[38981] D/I2C: send stop condition
Success
data 0x21 :4e ff
[38988] D/I2C: msgs[0] W, addr=0x52, len=1
[38992] D/I2C: msgs[1] R, addr=0x52, len=2
[38996] D/I2C: send start condition
[39000] D/I2C: ACK
[39002] D/I2C: ACK
[39004] D/I2C: write 1 byte
[39007] D/I2C: ACK
[39009] D/I2C: recieve bytes: 0x2a, ACK
[39013] D/I2C: recieve bytes: 0xff, NACK
[39018] D/I2C: read 2 bytes
[39020] D/I2C: send stop condition
Success
data 0x22 :2a ff
[39027] D/I2C: msgs[0] W, addr=0x52, len=1
[39031] D/I2C: msgs[1] R, addr=0x52, len=2
[39035] D/I2C: send start condition
[39039] D/I2C: ACK
[39041] D/I2C: ACK
[39043] D/I2C: write 1 byte
[39046] D/I2C: ACK
[39048] D/I2C: recieve bytes: 0x00, ACK
[39052] D/I2C: recieve bytes: 0xff, NACK
[39056] D/I2C: read 2 bytes
[39059] D/I2C: send stop condition
Success
data 0x1E :0 ff
[39065] D/I2C: msgs[0] W, addr=0x52, len=1
[39070] D/I2C: msgs[1] R, addr=0x52, len=2
[39074] D/I2C: send start condition
[39078] D/I2C: ACK
[39080] D/I2C: ACK
[39082] D/I2C: write 1 byte
[39085] D/I2C: ACK
[39087] D/I2C: recieve bytes: 0x0f, ACK
[39091] D/I2C: recieve bytes: 0xff, NACK
[39095] D/I2C: read 2 bytes
[39098] D/I2C: send stop condition
Success
data 0x10 :f ff
msh />pcf85
pcf8574_sample
pcf8575_sample
msh />pcf857
pcf8574_sample
pcf8575_sample
msh />pcf8574
pcf8574_sample
msh />pcf85
pcf8574_sample
pcf8575_sample
msh />pcf857
pcf8574_sample
pcf8575_sample
msh />pcf8574
pcf8574_sample
msh />pcf8574_sample 2 0 0
[63854] D/I2C: I2C bus dev [i2c1] writing 1 bytes.
[63859] D/I2C: msgs[0] W, addr=0x52, len=1
[63863] D/I2C: send start condition
[63867] D/I2C: ACK
[63869] D/I2C: ACK
[63871] D/I2C: write 1 byte
[63874] D/I2C: send stop condition
[63878] D/I2C: msgs[0] W, addr=0x52, len=2
[63882] D/I2C: send start condition
[63886] D/I2C: ACK
[63888] D/I2C: ACK
[63890] D/I2C: ACK
[63892] D/I2C: write 2 bytes
[63895] D/I2C: send stop condition
Success
[63900] D/I2C: msgs[0] W, addr=0x52, len=2
[63904] D/I2C: send start condition
[63908] D/I2C: ACK
[63910] D/I2C: ACK
[63912] D/I2C: ACK
[63914] D/I2C: write 2 bytes
[63917] D/I2C: send stop condition
Success
[63921] D/I2C: msgs[0] W, addr=0x52, len=2
[63926] D/I2C: send start condition
[63929] D/I2C: ACK
[63932] D/I2C: wait 1 tick for SCL line to go high
[63937] D/I2C: ACK
[63939] D/I2C: ACK
[63941] D/I2C: write 2 bytes
[63944] D/I2C: send stop condition
Success
[63948] D/I2C: msgs[0] W, addr=0x52, len=2
[63953] D/I2C: send start condition
[63956] D/I2C: ACK
[63958] D/I2C: ACK
[63961] D/I2C: wait 1 tick for SCL line to go high
[63966] D/I2C: ACK
[63968] D/I2C: write 2 bytes
[63971] D/I2C: send stop condition
Success
[63975] D/I2C: msgs[0] W, addr=0x52, len=2
[63979] D/I2C: send start condition
[63983] D/I2C: ACK
[63985] D/I2C: ACK
[63987] D/I2C: ACK
[63989] D/I2C: write 2 bytes
[63992] D/I2C: send stop condition
Success
[63997] D/I2C: msgs[0] W, addr=0x52, len=2
[64001] D/I2C: send start condition
[64005] D/I2C: ACK
[64007] D/I2C: ACK
[64009] D/I2C: ACK
[64011] D/I2C: write 2 bytes
[64014] D/I2C: send stop condition
Success
[64019] D/I2C: msgs[0] W, addr=0x52, len=1
[64023] D/I2C: msgs[1] R, addr=0x52, len=2
[64027] D/I2C: send start condition
[64031] D/I2C: ACK
[64033] D/I2C: ACK
[64035] D/I2C: write 1 byte
[64038] D/I2C: ACK
[64040] D/I2C: recieve bytes: 0x40, ACK
[64044] D/I2C: recieve bytes: 0xff, NACK
[64048] D/I2C: read 2 bytes
[64051] D/I2C: send stop condition
Success
data 0x03 :40 ff
[64057] D/I2C: msgs[0] W, addr=0x52, len=1
[64062] D/I2C: msgs[1] R, addr=0x52, len=2
[64066] D/I2C: send start condition
[64070] D/I2C: ACK
[64072] D/I2C: ACK
[64074] D/I2C: write 1 byte
[64077] D/I2C: ACK
[64079] D/I2C: recieve bytes: 0x80, ACK
[64083] D/I2C: recieve bytes: 0xff, NACK
[64087] D/I2C: read 2 bytes
[64090] D/I2C: send stop condition
Success
data 0x01 :80 ff
[64096] D/I2C: msgs[0] W, addr=0x52, len=1
[64101] D/I2C: msgs[1] R, addr=0x52, len=2
[64105] D/I2C: send start condition
[64109] D/I2C: ACK
[64111] D/I2C: ACK
[64113] D/I2C: write 1 byte
[64116] D/I2C: ACK
[64118] D/I2C: recieve bytes: 0x80, ACK
[64122] D/I2C: recieve bytes: 0xff, NACK
[64126] D/I2C: read 2 bytes
[64129] D/I2C: send stop condition
Success
data 0x00 :80 ff
[64135] D/I2C: msgs[0] W, addr=0x52, len=1
[64140] D/I2C: msgs[1] R, addr=0x52, len=2
[64144] D/I2C: send start condition
[64148] D/I2C: ACK
[64150] D/I2C: ACK
[64152] D/I2C: write 1 byte
[64155] D/I2C: ACK
[64157] D/I2C: recieve bytes: 0x40, ACK
[64161] D/I2C: recieve bytes: 0xff, NACK
[64165] D/I2C: read 2 bytes
[64168] D/I2C: send stop condition
Success
data 0x1b :40 ff
[64174] D/I2C: msgs[0] W, addr=0x52, len=1
[64179] D/I2C: msgs[1] R, addr=0x52, len=2
[64183] D/I2C: send start condition
[64187] D/I2C: ACK
[64189] D/I2C: ACK
[64191] D/I2C: write 1 byte
[64194] D/I2C: ACK
[64196] D/I2C: recieve bytes: 0x3f, ACK
[64200] D/I2C: recieve bytes: 0xff, NACK
[64204] D/I2C: read 2 bytes
[64207] D/I2C: send stop condition
Success
data 0x11 :3f ff
[64213] D/I2C: msgs[0] W, addr=0x52, len=1
[64218] D/I2C: msgs[1] R, addr=0x52, len=2
[64222] D/I2C: send start condition
[64226] D/I2C: ACK
[64228] D/I2C: ACK
[64230] D/I2C: write 1 byte
[64233] D/I2C: ACK
[64235] D/I2C: recieve bytes: 0xff, ACK
[64239] D/I2C: recieve bytes: 0xff, NACK
[64243] D/I2C: read 2 bytes
[64246] D/I2C: send stop condition
Success
data 0x12 :ff ff
[64252] D/I2C: msgs[0] W, addr=0x52, len=1
[64257] D/I2C: msgs[1] R, addr=0x52, len=2
[64261] D/I2C: send start condition
[64265] D/I2C: ACK
[64267] D/I2C: ACK
[64269] D/I2C: write 1 byte
[64272] D/I2C: ACK
[64274] D/I2C: recieve bytes: 0x4e, ACK
[64278] D/I2C: recieve bytes: 0xff, NACK
[64282] D/I2C: read 2 bytes
[64285] D/I2C: send stop condition
Success
data 0x21 :4e ff
[64291] D/I2C: msgs[0] W, addr=0x52, len=1
[64296] D/I2C: msgs[1] R, addr=0x52, len=2
[64300] D/I2C: send start condition
[64304] D/I2C: ACK
[64306] D/I2C: ACK
[64308] D/I2C: write 1 byte
[64311] D/I2C: ACK
[64313] D/I2C: recieve bytes: 0x2a, ACK
[64317] D/I2C: recieve bytes: 0xff, NACK
[64321] D/I2C: read 2 bytes
[64324] D/I2C: send stop condition
Success
data 0x22 :2a ff
[64330] D/I2C: msgs[0] W, addr=0x52, len=1
[64334] D/I2C: msgs[1] R, addr=0x52, len=2
[64339] D/I2C: send start condition
[64343] D/I2C: ACK
[64345] D/I2C: ACK
[64347] D/I2C: write 1 byte
[64350] D/I2C: ACK
[64352] D/I2C: recieve bytes: 0x00, ACK
[64356] D/I2C: recieve bytes: 0xff, NACK
[64360] D/I2C: read 2 bytes
[64363] D/I2C: send stop condition
Success
data 0x1E :0 ff
[64369] D/I2C: msgs[0] W, addr=0x52, len=1
[64373] D/I2C: msgs[1] R, addr=0x52, len=2
[64378] D/I2C: send start condition
[64381] D/I2C: ACK
[64384] D/I2C: wait 1 tick for SCL line to go high
[64389] D/I2C: ACK
[64391] D/I2C: write 1 byte
[64394] D/I2C: ACK
[64396] D/I2C: recieve bytes: 0x0f, ACK
[64400] D/I2C: recieve bytes: 0xff, NACK
[64404] D/I2C: read 2 bytes
[64407] D/I2C: send stop condition
Success
data 0x10 :f ff
msh />pcf85
pcf8574_sample
pcf8575_sample
msh />pcf857
pcf8574_sample
pcf8575_sample
msh />pcf8574
pcf8574_sample
msh />pcf8574_sample 3 0 0
[71417] D/I2C: I2C bus dev [i2c1] writing 1 bytes.
[71422] D/I2C: msgs[0] W, addr=0x52, len=1
[71426] D/I2C: send start condition
[71430] D/I2C: ACK
[71432] D/I2C: ACK
[71434] D/I2C: write 1 byte
[71437] D/I2C: send stop condition
[71441] D/I2C: msgs[0] W, addr=0x52, len=1
[71445] D/I2C: msgs[1] R, addr=0x52, len=2
[71449] D/I2C: send start condition
[71453] D/I2C: ACK
[71455] D/I2C: ACK
[71457] D/I2C: write 1 byte
[71460] D/I2C: ACK
[71462] D/I2C: recieve bytes: 0x00, ACK
[71466] D/I2C: recieve bytes: 0xff, NACK
[71471] D/I2C: read 2 bytes
[71473] D/I2C: send stop condition
Success
data 0x03 :0 ff
[71479] D/I2C: msgs[0] W, addr=0x52, len=1
[71484] D/I2C: msgs[1] R, addr=0x52, len=2
[71488] D/I2C: send start condition
[71492] D/I2C: ACK
[71494] D/I2C: ACK
[71496] D/I2C: write 1 byte
[71499] D/I2C: ACK
[71501] D/I2C: recieve bytes: 0x00, ACK
[71505] D/I2C: recieve bytes: 0xff, NACK
[71509] D/I2C: read 2 bytes
[71512] D/I2C: send stop condition
Success
data 0x01 :0 ff
[71518] D/I2C: msgs[0] W, addr=0x52, len=1
[71523] D/I2C: msgs[1] R, addr=0x52, len=2
[71527] D/I2C: send start condition
[71531] D/I2C: ACK
[71533] D/I2C: ACK
[71535] D/I2C: write 1 byte
[71538] D/I2C: ACK
[71540] D/I2C: recieve bytes: 0x00, ACK
[71544] D/I2C: recieve bytes: 0xff, NACK
[71548] D/I2C: read 2 bytes
[71551] D/I2C: send stop condition
Success
data 0x00 :0 ff
[71557] D/I2C: msgs[0] W, addr=0x52, len=1
[71562] D/I2C: msgs[1] R, addr=0x52, len=2
[71566] D/I2C: send start condition
[71570] D/I2C: ACK
[71572] D/I2C: ACK
[71574] D/I2C: write 1 byte
[71577] D/I2C: ACK
[71579] D/I2C: recieve bytes: 0xff, ACK
[71583] D/I2C: recieve bytes: 0xff, NACK
[71587] D/I2C: read 2 bytes
[71590] D/I2C: send stop condition
Success
data 0x1b :ff ff
[71596] D/I2C: msgs[0] W, addr=0x52, len=1
[71600] D/I2C: msgs[1] R, addr=0x52, len=2
[71605] D/I2C: send start condition
[71609] D/I2C: ACK
[71611] D/I2C: ACK
[71613] D/I2C: write 1 byte
[71616] D/I2C: ACK
[71618] D/I2C: recieve bytes: 0x3f, ACK
[71622] D/I2C: recieve bytes: 0xff, NACK
[71626] D/I2C: read 2 bytes
[71629] D/I2C: send stop condition
Success
data 0x11 :3f ff
[71635] D/I2C: msgs[0] W, addr=0x52, len=1
[71639] D/I2C: msgs[1] R, addr=0x52, len=2
[71644] D/I2C: send start condition
[71647] D/I2C: ACK
[71650] D/I2C: ACK
[71652] D/I2C: write 1 byte
[71655] D/I2C: ACK
[71657] D/I2C: recieve bytes: 0xff, ACK
[71661] D/I2C: recieve bytes: 0xff, NACK
[71665] D/I2C: read 2 bytes
[71668] D/I2C: send stop condition
Success
data 0x12 :ff ff
[71674] D/I2C: msgs[0] W, addr=0x52, len=1
[71678] D/I2C: msgs[1] R, addr=0x52, len=2
[71683] D/I2C: send start condition
[71686] D/I2C: ACK
[71689] D/I2C: ACK
[71691] D/I2C: write 1 byte
[71694] D/I2C: ACK
[71696] D/I2C: recieve bytes: 0x4e, ACK
[71700] D/I2C: recieve bytes: 0xff, NACK
[71704] D/I2C: read 2 bytes
[71707] D/I2C: send stop condition
Success
data 0x21 :4e ff
[71713] D/I2C: msgs[0] W, addr=0x52, len=1
[71717] D/I2C: msgs[1] R, addr=0x52, len=2
[71722] D/I2C: send start condition
[71725] D/I2C: ACK
[71728] D/I2C: ACK
[71730] D/I2C: write 1 byte
[71733] D/I2C: ACK
[71735] D/I2C: recieve bytes: 0x2a, ACK
[71739] D/I2C: recieve bytes: 0xff, NACK
[71743] D/I2C: read 2 bytes
[71746] D/I2C: send stop condition
Success
data 0x22 :2a ff
[71752] D/I2C: msgs[0] W, addr=0x52, len=1
[71756] D/I2C: msgs[1] R, addr=0x52, len=2
[71761] D/I2C: send start condition
[71764] D/I2C: ACK
[71766] D/I2C: ACK
[71768] D/I2C: write 1 byte
[71771] D/I2C: ACK
[71774] D/I2C: recieve bytes: 0x00, ACK
[71778] D/I2C: recieve bytes: 0xff, NACK
[71782] D/I2C: read 2 bytes
[71785] D/I2C: send stop condition
Success
data 0x1E :0 ff
[71791] D/I2C: msgs[0] W, addr=0x52, len=1
[71795] D/I2C: msgs[1] R, addr=0x52, len=2
[71799] D/I2C: send start condition
[71803] D/I2C: ACK
[71805] D/I2C: ACK
[71807] D/I2C: write 1 byte
[71810] D/I2C: ACK
[71812] D/I2C: recieve bytes: 0x0f, ACK
[71817] D/I2C: recieve bytes: 0xff, NACK
[71821] D/I2C: read 2 bytes
[71824] D/I2C: send stop condition
Success
data 0x10 :f ff
msh />

写入相关控制速度的寄存器以后,发现,还是不行,同时读取状态寄存器和错误码寄存器,发现无错误。

怎么办,那只能,上开发板了。

-99$

真贵啊,但是到货挺快的,在连上开发板以后,可以使用Ti官方提供的GUI软件来可视化动态配置相关参数和读取芯片的状态。

3.解决方式

第一步,点击红色按钮 Enable Configure,变成绿色以后就能修改相关的配置了。

首先把IPD这个勾给取消掉

然后输入电机参数,一个是相到中心的电阻,一个是电机的BEMF,前者是相间电阻/2,后者通过TI官方的计算公式算出

然后修改下图设置,红线部分在启动验证的时候可以使用默认值,然后勾上Closed Loop Disable,先让电机在开环状态下正常跑起来。

 完成以后切换到Disaplay界面,按下图设置,Speed按需求设置,然后点击 Manual Refresh。这时你设置参数正常,以及电机连接正常的时候,电机应该已经开始运动了。

 如果开环能正常运行,只是速度比较慢,那这时候我们再把前面Closed Loop Disable的勾取消,让它能正常运行在闭环状态。

最后别忘了保存配置表

4.参数烧写之前的驱动板

连接IIC以后,运行官方的烧写程序,把正确的配置烧写进去,我们之前不能正常跑的驱动板,也能跑了。

代码如下


#include "msp430.h"
#include "Register_Values.h"

#define SDA_1       P1OUT |=  BIT6              //SDA = 1
#define SDA_0       P1OUT &=~ BIT6              //SDA = 0
#define SCL_1       P2OUT |=  BIT5              //SCL = 1
#define SCL_0       P2OUT &=~ BIT5              //SCL = 0
#define DIR_IN      P1DIR &=~ BIT6;             //SDA Input
#define DIR_OUT     P1DIR |=  BIT6              //SDA Output
#define SDA_IN      ((P1IN >> 6) & 0x01)        //Read SDA

#define LED_ON      P1OUT |= BIT0
#define LED_OFF     P1OUT &=~BIT0

unsigned int r_result_all[12];
unsigned int end_result=1;
unsigned int write_data_all[]={REG_20, REG_21, REG_22, REG_23, REG_24, REG_25,
                               REG_26, REG_27, REG_28, REG_29, REG_2A, REG_2B};

static void Delay(unsigned int n)
{
   unsigned int i;
   for (i=0; i<n; i++ );
}

void Init(void)
{
  SCL_1;
  Delay(5);
  SDA_1;
  Delay(5);
}

void Start(void)
{
  SDA_1;
  Delay(5);
  SCL_1;
  Delay(5);
  SDA_0;
  Delay(5);
  SCL_0;
  Delay(5);
}

void Stop(void)
{
  SDA_0;
  Delay(5);
  SCL_1;
  Delay(5);
  SDA_1;
  Delay(5);
}

void WriteByte(unsigned char WriteData)
{
  unsigned char i;
  for (i=0; i<8; i++)
  {
    SCL_0;
    Delay(5);
    if (((WriteData >> 7) & 0x01) == 0x01)
    {
      SDA_1;
    }
    else
    {
      SDA_0;
    }
    Delay(5);
    SCL_1;
    WriteData = WriteData << 1;
    Delay(5);
  }
  SCL_0;
  DIR_IN;
  Delay(5);
  SCL_1;
  Delay(5);
  SCL_0;
  DIR_OUT;
}

unsigned char ReadByte(void)
{
  unsigned char i;
  unsigned char TempBit  = 0;
  unsigned char TempData = 0;
  SCL_0;
  Delay(5);
  SDA_1;
  for (i=0; i<8; i++)
  {
    Delay(5);
    SCL_1;
    Delay(5);
    if (SDA_IN == 0x01 )
    {
      TempBit = 1;
    }
    else
    {
      TempBit = 0;
    }
    TempData = (TempData << 1) | TempBit;
    SCL_0;
  }
  Delay(5);
  return(TempData);
}

void ReceiveAck(void)
{
  unsigned char i = 0;
  SCL_1;
  Delay(5);
  DIR_IN;
  while ((SDA_IN == 0x01) && (i < 255))
  {
    i++;
  }
  DIR_OUT;
  SCL_0;
  Delay(5);
}

void Acknowledge(void)
{
  SCL_0;
  Delay(5);
  DIR_OUT;
  SDA_0;
  SCL_1;
  Delay(5);
  SCL_0;
}

void main(void)
{
  unsigned int i;
  unsigned int vcc=0;
  WDTCTL = WDTPW + WDTHOLD;   // Stop Watchdog Timer
  BCSCTL1 = CALBC1_1MHZ; 	  // set up the clocks
  DCOCTL = CALDCO_1MHZ;
  
  DIR_OUT;
  P2DIR |= BIT5;  //clock as an output
  P1DIR |= BIT0;  //LED as an output
  LED_OFF;
  P1DIR &=~ BIT3; //push button input
  P1REN |= BIT3;  //enable the pull up
  P1OUT |=  BIT3; //set the pull up
  
  while(vcc<0xBB) //wait for VCC to be 22V
  {
  //begin read command for 0x1A
  Start();
  WriteByte(0xA4);
  WriteByte(0x1A);
  Stop();

  //read 0x1A
  Start();
  WriteByte(0xA5);
  P1OUT &=~BIT6;
  P1REN &=~BIT6;
  DIR_IN;

  //read register with Nack
  vcc=ReadByte();
  Acknowledge();
  Stop();
  }

  while(((P1IN >> 3) & 0x01)); //wait for push button

  //set Sidata bit to 1
  Start();
  WriteByte(0xA4);
  WriteByte(0x03);
  WriteByte(0x40);
  Stop();


  for(i=0; i<12; i++)
  {
	//write each register 0x20 to 0x2B
    Start();
    WriteByte(0xA4);
    WriteByte(0x20+i);
    WriteByte(write_data_all[i]);
    Stop();
  }
  
  //enter the program key
  Start();
  WriteByte(0xA4);
  WriteByte(0x02);
  WriteByte(0xB6);
  Stop();

  //set eeWrite to 1
  Start();
  WriteByte(0xA4);
  WriteByte(0x03);
  WriteByte(0x50);
  Stop();

  //delay to allow eeWrite to finish
  for(i=0;i<20000;i++)
  {
	  Delay(10000);
  }

  //set eeRefresh bit
  Start();
  WriteByte(0xA4);
  WriteByte(0x03);
  WriteByte(0x20);
  Stop();


  for(i=0;i<12;i++)
  {
	//begin the read command for each register
    Start();
    WriteByte(0xA4);
    WriteByte(0x20+i);
    Stop();
  
    //send the read command for each register
    Start();
    WriteByte(0xA5);
    P1OUT &=~BIT6;
    P1REN &=~BIT6;
    DIR_IN;
    
    ///read register with Nack
    r_result_all[i]=ReadByte();
    Acknowledge();
    Stop();
    
    //compare each register value read to the write
    //register 8 bit 0 can be 0 or 1 so shift right to compare
    if(r_result_all[i] == write_data_all[i])
      end_result &= 1;
    else if(r_result_all[8]>>1 == write_data_all[8]>>1)
      end_result &= 1;
    else
      end_result=0;
  }
    //if all reads match writes turn the LED ON
    if(end_result)
      LED_ON;
    else
      LED_OFF;
  
    //loop forever
    while (1);
  
}

 

 5.总结

 在使用一款新的驱动芯片做验证时,还是购买官方的开发板来验证比较靠谱。

版权声明:本文为CSDN博主「明日紊潮」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43990384/article/details/122185138

因为工作需要,目前在验证DRV10983这块驱动芯片是否能满足我们驱动无刷电机的需求。不出意料踩了坑,看了看官网论坛也有类似的问题,索性分享出来让大家少走点弯路。

 

1.问题描述

首先,我们来看看它的数据手册

看到可以直接通过PWM或者I2C输入控制电机,于是硬件交给我板子的时候说,“你接个PWM应该就能动了。”然后我输出了一路PWM波,接上去,它抖了一下,动了,转了。

然后10秒以后就停了。

咋回事啊?

2.原因分析

翻查数据手册,对比了一下,我输出的这路PWM波高低电平和频率都符合要求,输入的电压也没有问题。那么问题应该是在芯片这里了。或许应该使用i2c来写速度?

于是接了SDA和SCL出来连I2C,在正常通讯以后,也读到了相关的配置。

msh />pcf8574_sample 2 0 0
[38561] D/I2C: I2C bus dev [i2c1] writing 1 bytes.
[38566] D/I2C: msgs[0] W, addr=0x52, len=1
[38570] D/I2C: send start condition
[38574] D/I2C: ACK
[38576] D/I2C: ACK
[38578] D/I2C: write 1 byte
[38581] D/I2C: send stop condition
[38584] D/I2C: msgs[0] W, addr=0x52, len=2
[38589] D/I2C: send start condition
[38592] D/I2C: ACK
[38595] D/I2C: ACK
[38597] D/I2C: ACK
[38599] D/I2C: write 2 bytes
[38602] D/I2C: send stop condition
Success
[38606] D/I2C: msgs[0] W, addr=0x52, len=2
[38610] D/I2C: send start condition
[38614] D/I2C: ACK
[38616] D/I2C: ACK
[38618] D/I2C: ACK
[38621] D/I2C: write 2 bytes
[38623] D/I2C: send stop condition
Success
[38628] D/I2C: msgs[0] W, addr=0x52, len=2
[38632] D/I2C: send start condition
[38636] D/I2C: ACK
[38638] D/I2C: ACK
[38640] D/I2C: ACK
[38642] D/I2C: write 2 bytes
[38645] D/I2C: send stop condition
Success
[38650] D/I2C: msgs[0] W, addr=0x52, len=2
[38654] D/I2C: send start condition
[38658] D/I2C: ACK
[38660] D/I2C: ACK
[38662] D/I2C: ACK
[38664] D/I2C: write 2 bytes
[38667] D/I2C: send stop condition
Success
[38671] D/I2C: msgs[0] W, addr=0x52, len=2
[38676] D/I2C: send start condition
[38679] D/I2C: ACK
[38682] D/I2C: ACK
[38684] D/I2C: ACK
[38686] D/I2C: write 2 bytes
[38689] D/I2C: send stop condition
Success
[38693] D/I2C: msgs[0] W, addr=0x52, len=2
[38697] D/I2C: send start condition
[38701] D/I2C: ACK
[38703] D/I2C: ACK
[38705] D/I2C: ACK
[38708] D/I2C: write 2 bytes
[38710] D/I2C: send stop condition
Success
[38715] D/I2C: msgs[0] W, addr=0x52, len=1
[38719] D/I2C: msgs[1] R, addr=0x52, len=2
[38724] D/I2C: send start condition
[38727] D/I2C: ACK
[38729] D/I2C: ACK
[38731] D/I2C: write 1 byte
[38734] D/I2C: ACK
[38737] D/I2C: recieve bytes: 0x40, ACK
[38741] D/I2C: recieve bytes: 0xff, NACK
[38745] D/I2C: read 2 bytes
[38748] D/I2C: send stop condition
Success
data 0x03 :40 ff
[38754] D/I2C: msgs[0] W, addr=0x52, len=1
[38758] D/I2C: msgs[1] R, addr=0x52, len=2
[38763] D/I2C: send start condition
[38766] D/I2C: ACK
[38768] D/I2C: ACK
[38770] D/I2C: write 1 byte
[38773] D/I2C: ACK
[38776] D/I2C: recieve bytes: 0x80, ACK
[38780] D/I2C: recieve bytes: 0xff, NACK
[38784] D/I2C: read 2 bytes
[38787] D/I2C: send stop condition
Success
data 0x01 :80 ff
[38793] D/I2C: msgs[0] W, addr=0x52, len=1
[38797] D/I2C: msgs[1] R, addr=0x52, len=2
[38801] D/I2C: send start condition
[38805] D/I2C: ACK
[38807] D/I2C: ACK
[38809] D/I2C: write 1 byte
[38812] D/I2C: ACK
[38814] D/I2C: recieve bytes: 0x80, ACK
[38819] D/I2C: recieve bytes: 0xff, NACK
[38823] D/I2C: read 2 bytes
[38826] D/I2C: send stop condition
Success
data 0x00 :80 ff
[38832] D/I2C: msgs[0] W, addr=0x52, len=1
[38836] D/I2C: msgs[1] R, addr=0x52, len=2
[38840] D/I2C: send start condition
[38844] D/I2C: ACK
[38846] D/I2C: ACK
[38848] D/I2C: write 1 byte
[38851] D/I2C: ACK
[38853] D/I2C: recieve bytes: 0x40, ACK
[38858] D/I2C: recieve bytes: 0xff, NACK
[38862] D/I2C: read 2 bytes
[38865] D/I2C: send stop condition
Success
data 0x1b :40 ff
[38871] D/I2C: msgs[0] W, addr=0x52, len=1
[38875] D/I2C: msgs[1] R, addr=0x52, len=2
[38879] D/I2C: send start condition
[38883] D/I2C: ACK
[38885] D/I2C: ACK
[38887] D/I2C: write 1 byte
[38890] D/I2C: ACK
[38892] D/I2C: recieve bytes: 0x3f, ACK
[38897] D/I2C: recieve bytes: 0xff, NACK
[38901] D/I2C: read 2 bytes
[38904] D/I2C: send stop condition
Success
data 0x11 :3f ff
[38910] D/I2C: msgs[0] W, addr=0x52, len=1
[38914] D/I2C: msgs[1] R, addr=0x52, len=2
[38918] D/I2C: send start condition
[38922] D/I2C: ACK
[38924] D/I2C: ACK
[38926] D/I2C: write 1 byte
[38929] D/I2C: ACK
[38931] D/I2C: recieve bytes: 0xff, ACK
[38935] D/I2C: recieve bytes: 0xff, NACK
[38940] D/I2C: read 2 bytes
[38943] D/I2C: send stop condition
Success
data 0x12 :ff ff
[38949] D/I2C: msgs[0] W, addr=0x52, len=1
[38953] D/I2C: msgs[1] R, addr=0x52, len=2
[38957] D/I2C: send start condition
[38961] D/I2C: ACK
[38963] D/I2C: ACK
[38965] D/I2C: write 1 byte
[38968] D/I2C: ACK
[38970] D/I2C: recieve bytes: 0x4e, ACK
[38974] D/I2C: recieve bytes: 0xff, NACK
[38979] D/I2C: read 2 bytes
[38981] D/I2C: send stop condition
Success
data 0x21 :4e ff
[38988] D/I2C: msgs[0] W, addr=0x52, len=1
[38992] D/I2C: msgs[1] R, addr=0x52, len=2
[38996] D/I2C: send start condition
[39000] D/I2C: ACK
[39002] D/I2C: ACK
[39004] D/I2C: write 1 byte
[39007] D/I2C: ACK
[39009] D/I2C: recieve bytes: 0x2a, ACK
[39013] D/I2C: recieve bytes: 0xff, NACK
[39018] D/I2C: read 2 bytes
[39020] D/I2C: send stop condition
Success
data 0x22 :2a ff
[39027] D/I2C: msgs[0] W, addr=0x52, len=1
[39031] D/I2C: msgs[1] R, addr=0x52, len=2
[39035] D/I2C: send start condition
[39039] D/I2C: ACK
[39041] D/I2C: ACK
[39043] D/I2C: write 1 byte
[39046] D/I2C: ACK
[39048] D/I2C: recieve bytes: 0x00, ACK
[39052] D/I2C: recieve bytes: 0xff, NACK
[39056] D/I2C: read 2 bytes
[39059] D/I2C: send stop condition
Success
data 0x1E :0 ff
[39065] D/I2C: msgs[0] W, addr=0x52, len=1
[39070] D/I2C: msgs[1] R, addr=0x52, len=2
[39074] D/I2C: send start condition
[39078] D/I2C: ACK
[39080] D/I2C: ACK
[39082] D/I2C: write 1 byte
[39085] D/I2C: ACK
[39087] D/I2C: recieve bytes: 0x0f, ACK
[39091] D/I2C: recieve bytes: 0xff, NACK
[39095] D/I2C: read 2 bytes
[39098] D/I2C: send stop condition
Success
data 0x10 :f ff
msh />pcf85
pcf8574_sample
pcf8575_sample
msh />pcf857
pcf8574_sample
pcf8575_sample
msh />pcf8574
pcf8574_sample
msh />pcf85
pcf8574_sample
pcf8575_sample
msh />pcf857
pcf8574_sample
pcf8575_sample
msh />pcf8574
pcf8574_sample
msh />pcf8574_sample 2 0 0
[63854] D/I2C: I2C bus dev [i2c1] writing 1 bytes.
[63859] D/I2C: msgs[0] W, addr=0x52, len=1
[63863] D/I2C: send start condition
[63867] D/I2C: ACK
[63869] D/I2C: ACK
[63871] D/I2C: write 1 byte
[63874] D/I2C: send stop condition
[63878] D/I2C: msgs[0] W, addr=0x52, len=2
[63882] D/I2C: send start condition
[63886] D/I2C: ACK
[63888] D/I2C: ACK
[63890] D/I2C: ACK
[63892] D/I2C: write 2 bytes
[63895] D/I2C: send stop condition
Success
[63900] D/I2C: msgs[0] W, addr=0x52, len=2
[63904] D/I2C: send start condition
[63908] D/I2C: ACK
[63910] D/I2C: ACK
[63912] D/I2C: ACK
[63914] D/I2C: write 2 bytes
[63917] D/I2C: send stop condition
Success
[63921] D/I2C: msgs[0] W, addr=0x52, len=2
[63926] D/I2C: send start condition
[63929] D/I2C: ACK
[63932] D/I2C: wait 1 tick for SCL line to go high
[63937] D/I2C: ACK
[63939] D/I2C: ACK
[63941] D/I2C: write 2 bytes
[63944] D/I2C: send stop condition
Success
[63948] D/I2C: msgs[0] W, addr=0x52, len=2
[63953] D/I2C: send start condition
[63956] D/I2C: ACK
[63958] D/I2C: ACK
[63961] D/I2C: wait 1 tick for SCL line to go high
[63966] D/I2C: ACK
[63968] D/I2C: write 2 bytes
[63971] D/I2C: send stop condition
Success
[63975] D/I2C: msgs[0] W, addr=0x52, len=2
[63979] D/I2C: send start condition
[63983] D/I2C: ACK
[63985] D/I2C: ACK
[63987] D/I2C: ACK
[63989] D/I2C: write 2 bytes
[63992] D/I2C: send stop condition
Success
[63997] D/I2C: msgs[0] W, addr=0x52, len=2
[64001] D/I2C: send start condition
[64005] D/I2C: ACK
[64007] D/I2C: ACK
[64009] D/I2C: ACK
[64011] D/I2C: write 2 bytes
[64014] D/I2C: send stop condition
Success
[64019] D/I2C: msgs[0] W, addr=0x52, len=1
[64023] D/I2C: msgs[1] R, addr=0x52, len=2
[64027] D/I2C: send start condition
[64031] D/I2C: ACK
[64033] D/I2C: ACK
[64035] D/I2C: write 1 byte
[64038] D/I2C: ACK
[64040] D/I2C: recieve bytes: 0x40, ACK
[64044] D/I2C: recieve bytes: 0xff, NACK
[64048] D/I2C: read 2 bytes
[64051] D/I2C: send stop condition
Success
data 0x03 :40 ff
[64057] D/I2C: msgs[0] W, addr=0x52, len=1
[64062] D/I2C: msgs[1] R, addr=0x52, len=2
[64066] D/I2C: send start condition
[64070] D/I2C: ACK
[64072] D/I2C: ACK
[64074] D/I2C: write 1 byte
[64077] D/I2C: ACK
[64079] D/I2C: recieve bytes: 0x80, ACK
[64083] D/I2C: recieve bytes: 0xff, NACK
[64087] D/I2C: read 2 bytes
[64090] D/I2C: send stop condition
Success
data 0x01 :80 ff
[64096] D/I2C: msgs[0] W, addr=0x52, len=1
[64101] D/I2C: msgs[1] R, addr=0x52, len=2
[64105] D/I2C: send start condition
[64109] D/I2C: ACK
[64111] D/I2C: ACK
[64113] D/I2C: write 1 byte
[64116] D/I2C: ACK
[64118] D/I2C: recieve bytes: 0x80, ACK
[64122] D/I2C: recieve bytes: 0xff, NACK
[64126] D/I2C: read 2 bytes
[64129] D/I2C: send stop condition
Success
data 0x00 :80 ff
[64135] D/I2C: msgs[0] W, addr=0x52, len=1
[64140] D/I2C: msgs[1] R, addr=0x52, len=2
[64144] D/I2C: send start condition
[64148] D/I2C: ACK
[64150] D/I2C: ACK
[64152] D/I2C: write 1 byte
[64155] D/I2C: ACK
[64157] D/I2C: recieve bytes: 0x40, ACK
[64161] D/I2C: recieve bytes: 0xff, NACK
[64165] D/I2C: read 2 bytes
[64168] D/I2C: send stop condition
Success
data 0x1b :40 ff
[64174] D/I2C: msgs[0] W, addr=0x52, len=1
[64179] D/I2C: msgs[1] R, addr=0x52, len=2
[64183] D/I2C: send start condition
[64187] D/I2C: ACK
[64189] D/I2C: ACK
[64191] D/I2C: write 1 byte
[64194] D/I2C: ACK
[64196] D/I2C: recieve bytes: 0x3f, ACK
[64200] D/I2C: recieve bytes: 0xff, NACK
[64204] D/I2C: read 2 bytes
[64207] D/I2C: send stop condition
Success
data 0x11 :3f ff
[64213] D/I2C: msgs[0] W, addr=0x52, len=1
[64218] D/I2C: msgs[1] R, addr=0x52, len=2
[64222] D/I2C: send start condition
[64226] D/I2C: ACK
[64228] D/I2C: ACK
[64230] D/I2C: write 1 byte
[64233] D/I2C: ACK
[64235] D/I2C: recieve bytes: 0xff, ACK
[64239] D/I2C: recieve bytes: 0xff, NACK
[64243] D/I2C: read 2 bytes
[64246] D/I2C: send stop condition
Success
data 0x12 :ff ff
[64252] D/I2C: msgs[0] W, addr=0x52, len=1
[64257] D/I2C: msgs[1] R, addr=0x52, len=2
[64261] D/I2C: send start condition
[64265] D/I2C: ACK
[64267] D/I2C: ACK
[64269] D/I2C: write 1 byte
[64272] D/I2C: ACK
[64274] D/I2C: recieve bytes: 0x4e, ACK
[64278] D/I2C: recieve bytes: 0xff, NACK
[64282] D/I2C: read 2 bytes
[64285] D/I2C: send stop condition
Success
data 0x21 :4e ff
[64291] D/I2C: msgs[0] W, addr=0x52, len=1
[64296] D/I2C: msgs[1] R, addr=0x52, len=2
[64300] D/I2C: send start condition
[64304] D/I2C: ACK
[64306] D/I2C: ACK
[64308] D/I2C: write 1 byte
[64311] D/I2C: ACK
[64313] D/I2C: recieve bytes: 0x2a, ACK
[64317] D/I2C: recieve bytes: 0xff, NACK
[64321] D/I2C: read 2 bytes
[64324] D/I2C: send stop condition
Success
data 0x22 :2a ff
[64330] D/I2C: msgs[0] W, addr=0x52, len=1
[64334] D/I2C: msgs[1] R, addr=0x52, len=2
[64339] D/I2C: send start condition
[64343] D/I2C: ACK
[64345] D/I2C: ACK
[64347] D/I2C: write 1 byte
[64350] D/I2C: ACK
[64352] D/I2C: recieve bytes: 0x00, ACK
[64356] D/I2C: recieve bytes: 0xff, NACK
[64360] D/I2C: read 2 bytes
[64363] D/I2C: send stop condition
Success
data 0x1E :0 ff
[64369] D/I2C: msgs[0] W, addr=0x52, len=1
[64373] D/I2C: msgs[1] R, addr=0x52, len=2
[64378] D/I2C: send start condition
[64381] D/I2C: ACK
[64384] D/I2C: wait 1 tick for SCL line to go high
[64389] D/I2C: ACK
[64391] D/I2C: write 1 byte
[64394] D/I2C: ACK
[64396] D/I2C: recieve bytes: 0x0f, ACK
[64400] D/I2C: recieve bytes: 0xff, NACK
[64404] D/I2C: read 2 bytes
[64407] D/I2C: send stop condition
Success
data 0x10 :f ff
msh />pcf85
pcf8574_sample
pcf8575_sample
msh />pcf857
pcf8574_sample
pcf8575_sample
msh />pcf8574
pcf8574_sample
msh />pcf8574_sample 3 0 0
[71417] D/I2C: I2C bus dev [i2c1] writing 1 bytes.
[71422] D/I2C: msgs[0] W, addr=0x52, len=1
[71426] D/I2C: send start condition
[71430] D/I2C: ACK
[71432] D/I2C: ACK
[71434] D/I2C: write 1 byte
[71437] D/I2C: send stop condition
[71441] D/I2C: msgs[0] W, addr=0x52, len=1
[71445] D/I2C: msgs[1] R, addr=0x52, len=2
[71449] D/I2C: send start condition
[71453] D/I2C: ACK
[71455] D/I2C: ACK
[71457] D/I2C: write 1 byte
[71460] D/I2C: ACK
[71462] D/I2C: recieve bytes: 0x00, ACK
[71466] D/I2C: recieve bytes: 0xff, NACK
[71471] D/I2C: read 2 bytes
[71473] D/I2C: send stop condition
Success
data 0x03 :0 ff
[71479] D/I2C: msgs[0] W, addr=0x52, len=1
[71484] D/I2C: msgs[1] R, addr=0x52, len=2
[71488] D/I2C: send start condition
[71492] D/I2C: ACK
[71494] D/I2C: ACK
[71496] D/I2C: write 1 byte
[71499] D/I2C: ACK
[71501] D/I2C: recieve bytes: 0x00, ACK
[71505] D/I2C: recieve bytes: 0xff, NACK
[71509] D/I2C: read 2 bytes
[71512] D/I2C: send stop condition
Success
data 0x01 :0 ff
[71518] D/I2C: msgs[0] W, addr=0x52, len=1
[71523] D/I2C: msgs[1] R, addr=0x52, len=2
[71527] D/I2C: send start condition
[71531] D/I2C: ACK
[71533] D/I2C: ACK
[71535] D/I2C: write 1 byte
[71538] D/I2C: ACK
[71540] D/I2C: recieve bytes: 0x00, ACK
[71544] D/I2C: recieve bytes: 0xff, NACK
[71548] D/I2C: read 2 bytes
[71551] D/I2C: send stop condition
Success
data 0x00 :0 ff
[71557] D/I2C: msgs[0] W, addr=0x52, len=1
[71562] D/I2C: msgs[1] R, addr=0x52, len=2
[71566] D/I2C: send start condition
[71570] D/I2C: ACK
[71572] D/I2C: ACK
[71574] D/I2C: write 1 byte
[71577] D/I2C: ACK
[71579] D/I2C: recieve bytes: 0xff, ACK
[71583] D/I2C: recieve bytes: 0xff, NACK
[71587] D/I2C: read 2 bytes
[71590] D/I2C: send stop condition
Success
data 0x1b :ff ff
[71596] D/I2C: msgs[0] W, addr=0x52, len=1
[71600] D/I2C: msgs[1] R, addr=0x52, len=2
[71605] D/I2C: send start condition
[71609] D/I2C: ACK
[71611] D/I2C: ACK
[71613] D/I2C: write 1 byte
[71616] D/I2C: ACK
[71618] D/I2C: recieve bytes: 0x3f, ACK
[71622] D/I2C: recieve bytes: 0xff, NACK
[71626] D/I2C: read 2 bytes
[71629] D/I2C: send stop condition
Success
data 0x11 :3f ff
[71635] D/I2C: msgs[0] W, addr=0x52, len=1
[71639] D/I2C: msgs[1] R, addr=0x52, len=2
[71644] D/I2C: send start condition
[71647] D/I2C: ACK
[71650] D/I2C: ACK
[71652] D/I2C: write 1 byte
[71655] D/I2C: ACK
[71657] D/I2C: recieve bytes: 0xff, ACK
[71661] D/I2C: recieve bytes: 0xff, NACK
[71665] D/I2C: read 2 bytes
[71668] D/I2C: send stop condition
Success
data 0x12 :ff ff
[71674] D/I2C: msgs[0] W, addr=0x52, len=1
[71678] D/I2C: msgs[1] R, addr=0x52, len=2
[71683] D/I2C: send start condition
[71686] D/I2C: ACK
[71689] D/I2C: ACK
[71691] D/I2C: write 1 byte
[71694] D/I2C: ACK
[71696] D/I2C: recieve bytes: 0x4e, ACK
[71700] D/I2C: recieve bytes: 0xff, NACK
[71704] D/I2C: read 2 bytes
[71707] D/I2C: send stop condition
Success
data 0x21 :4e ff
[71713] D/I2C: msgs[0] W, addr=0x52, len=1
[71717] D/I2C: msgs[1] R, addr=0x52, len=2
[71722] D/I2C: send start condition
[71725] D/I2C: ACK
[71728] D/I2C: ACK
[71730] D/I2C: write 1 byte
[71733] D/I2C: ACK
[71735] D/I2C: recieve bytes: 0x2a, ACK
[71739] D/I2C: recieve bytes: 0xff, NACK
[71743] D/I2C: read 2 bytes
[71746] D/I2C: send stop condition
Success
data 0x22 :2a ff
[71752] D/I2C: msgs[0] W, addr=0x52, len=1
[71756] D/I2C: msgs[1] R, addr=0x52, len=2
[71761] D/I2C: send start condition
[71764] D/I2C: ACK
[71766] D/I2C: ACK
[71768] D/I2C: write 1 byte
[71771] D/I2C: ACK
[71774] D/I2C: recieve bytes: 0x00, ACK
[71778] D/I2C: recieve bytes: 0xff, NACK
[71782] D/I2C: read 2 bytes
[71785] D/I2C: send stop condition
Success
data 0x1E :0 ff
[71791] D/I2C: msgs[0] W, addr=0x52, len=1
[71795] D/I2C: msgs[1] R, addr=0x52, len=2
[71799] D/I2C: send start condition
[71803] D/I2C: ACK
[71805] D/I2C: ACK
[71807] D/I2C: write 1 byte
[71810] D/I2C: ACK
[71812] D/I2C: recieve bytes: 0x0f, ACK
[71817] D/I2C: recieve bytes: 0xff, NACK
[71821] D/I2C: read 2 bytes
[71824] D/I2C: send stop condition
Success
data 0x10 :f ff
msh />

写入相关控制速度的寄存器以后,发现,还是不行,同时读取状态寄存器和错误码寄存器,发现无错误。

怎么办,那只能,上开发板了。

-99$

真贵啊,但是到货挺快的,在连上开发板以后,可以使用Ti官方提供的GUI软件来可视化动态配置相关参数和读取芯片的状态。

3.解决方式

第一步,点击红色按钮 Enable Configure,变成绿色以后就能修改相关的配置了。

首先把IPD这个勾给取消掉

然后输入电机参数,一个是相到中心的电阻,一个是电机的BEMF,前者是相间电阻/2,后者通过TI官方的计算公式算出

然后修改下图设置,红线部分在启动验证的时候可以使用默认值,然后勾上Closed Loop Disable,先让电机在开环状态下正常跑起来。

 完成以后切换到Disaplay界面,按下图设置,Speed按需求设置,然后点击 Manual Refresh。这时你设置参数正常,以及电机连接正常的时候,电机应该已经开始运动了。

 如果开环能正常运行,只是速度比较慢,那这时候我们再把前面Closed Loop Disable的勾取消,让它能正常运行在闭环状态。

最后别忘了保存配置表

4.参数烧写之前的驱动板

连接IIC以后,运行官方的烧写程序,把正确的配置烧写进去,我们之前不能正常跑的驱动板,也能跑了。

代码如下


#include "msp430.h"
#include "Register_Values.h"

#define SDA_1       P1OUT |=  BIT6              //SDA = 1
#define SDA_0       P1OUT &=~ BIT6              //SDA = 0
#define SCL_1       P2OUT |=  BIT5              //SCL = 1
#define SCL_0       P2OUT &=~ BIT5              //SCL = 0
#define DIR_IN      P1DIR &=~ BIT6;             //SDA Input
#define DIR_OUT     P1DIR |=  BIT6              //SDA Output
#define SDA_IN      ((P1IN >> 6) & 0x01)        //Read SDA

#define LED_ON      P1OUT |= BIT0
#define LED_OFF     P1OUT &=~BIT0

unsigned int r_result_all[12];
unsigned int end_result=1;
unsigned int write_data_all[]={REG_20, REG_21, REG_22, REG_23, REG_24, REG_25,
                               REG_26, REG_27, REG_28, REG_29, REG_2A, REG_2B};

static void Delay(unsigned int n)
{
   unsigned int i;
   for (i=0; i<n; i++ );
}

void Init(void)
{
  SCL_1;
  Delay(5);
  SDA_1;
  Delay(5);
}

void Start(void)
{
  SDA_1;
  Delay(5);
  SCL_1;
  Delay(5);
  SDA_0;
  Delay(5);
  SCL_0;
  Delay(5);
}

void Stop(void)
{
  SDA_0;
  Delay(5);
  SCL_1;
  Delay(5);
  SDA_1;
  Delay(5);
}

void WriteByte(unsigned char WriteData)
{
  unsigned char i;
  for (i=0; i<8; i++)
  {
    SCL_0;
    Delay(5);
    if (((WriteData >> 7) & 0x01) == 0x01)
    {
      SDA_1;
    }
    else
    {
      SDA_0;
    }
    Delay(5);
    SCL_1;
    WriteData = WriteData << 1;
    Delay(5);
  }
  SCL_0;
  DIR_IN;
  Delay(5);
  SCL_1;
  Delay(5);
  SCL_0;
  DIR_OUT;
}

unsigned char ReadByte(void)
{
  unsigned char i;
  unsigned char TempBit  = 0;
  unsigned char TempData = 0;
  SCL_0;
  Delay(5);
  SDA_1;
  for (i=0; i<8; i++)
  {
    Delay(5);
    SCL_1;
    Delay(5);
    if (SDA_IN == 0x01 )
    {
      TempBit = 1;
    }
    else
    {
      TempBit = 0;
    }
    TempData = (TempData << 1) | TempBit;
    SCL_0;
  }
  Delay(5);
  return(TempData);
}

void ReceiveAck(void)
{
  unsigned char i = 0;
  SCL_1;
  Delay(5);
  DIR_IN;
  while ((SDA_IN == 0x01) && (i < 255))
  {
    i++;
  }
  DIR_OUT;
  SCL_0;
  Delay(5);
}

void Acknowledge(void)
{
  SCL_0;
  Delay(5);
  DIR_OUT;
  SDA_0;
  SCL_1;
  Delay(5);
  SCL_0;
}

void main(void)
{
  unsigned int i;
  unsigned int vcc=0;
  WDTCTL = WDTPW + WDTHOLD;   // Stop Watchdog Timer
  BCSCTL1 = CALBC1_1MHZ; 	  // set up the clocks
  DCOCTL = CALDCO_1MHZ;
  
  DIR_OUT;
  P2DIR |= BIT5;  //clock as an output
  P1DIR |= BIT0;  //LED as an output
  LED_OFF;
  P1DIR &=~ BIT3; //push button input
  P1REN |= BIT3;  //enable the pull up
  P1OUT |=  BIT3; //set the pull up
  
  while(vcc<0xBB) //wait for VCC to be 22V
  {
  //begin read command for 0x1A
  Start();
  WriteByte(0xA4);
  WriteByte(0x1A);
  Stop();

  //read 0x1A
  Start();
  WriteByte(0xA5);
  P1OUT &=~BIT6;
  P1REN &=~BIT6;
  DIR_IN;

  //read register with Nack
  vcc=ReadByte();
  Acknowledge();
  Stop();
  }

  while(((P1IN >> 3) & 0x01)); //wait for push button

  //set Sidata bit to 1
  Start();
  WriteByte(0xA4);
  WriteByte(0x03);
  WriteByte(0x40);
  Stop();


  for(i=0; i<12; i++)
  {
	//write each register 0x20 to 0x2B
    Start();
    WriteByte(0xA4);
    WriteByte(0x20+i);
    WriteByte(write_data_all[i]);
    Stop();
  }
  
  //enter the program key
  Start();
  WriteByte(0xA4);
  WriteByte(0x02);
  WriteByte(0xB6);
  Stop();

  //set eeWrite to 1
  Start();
  WriteByte(0xA4);
  WriteByte(0x03);
  WriteByte(0x50);
  Stop();

  //delay to allow eeWrite to finish
  for(i=0;i<20000;i++)
  {
	  Delay(10000);
  }

  //set eeRefresh bit
  Start();
  WriteByte(0xA4);
  WriteByte(0x03);
  WriteByte(0x20);
  Stop();


  for(i=0;i<12;i++)
  {
	//begin the read command for each register
    Start();
    WriteByte(0xA4);
    WriteByte(0x20+i);
    Stop();
  
    //send the read command for each register
    Start();
    WriteByte(0xA5);
    P1OUT &=~BIT6;
    P1REN &=~BIT6;
    DIR_IN;
    
    ///read register with Nack
    r_result_all[i]=ReadByte();
    Acknowledge();
    Stop();
    
    //compare each register value read to the write
    //register 8 bit 0 can be 0 or 1 so shift right to compare
    if(r_result_all[i] == write_data_all[i])
      end_result &= 1;
    else if(r_result_all[8]>>1 == write_data_all[8]>>1)
      end_result &= 1;
    else
      end_result=0;
  }
    //if all reads match writes turn the LED ON
    if(end_result)
      LED_ON;
    else
      LED_OFF;
  
    //loop forever
    while (1);
  
}

 

 5.总结

 在使用一款新的驱动芯片做验证时,还是购买官方的开发板来验证比较靠谱。

版权声明:本文为CSDN博主「明日紊潮」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43990384/article/details/122185138

生成海报
点赞 0

明日紊潮

我还没有学会写个人说明!

暂无评论

发表评论

相关推荐

基于8051单片机实现电子时钟+数字秒表设计

概述 电子时钟是一种利用数字电路来显示秒、分、时的计时装置,与传统的机械钟相比,它具有走时准确、显 示直观、无机械传动装置等优点,因而得到广泛应用。随着人们生活环境的不断改善和美化,在许

基于Arduino的显示测量环境数据设计

题目: 基于Arduino的显示测量环境数据设计 目录 基于Arduino的显示测量环境数据设计... 3 第一章 课题任务... 4 1.1课题任务... 4 1.2任务分工... 4 1.3设计条件... 4 第

串口不定长接收

一、保留接收区和开启接收的语句    uint8_t buffer[5];HAL_UART_Transmit_IT(&huart1,buffer,3); 二、写入开启空闲中断的语句    __HAL_UART_ENABLE_IT(&huart