目前针对于L99H92 的驱动探讨如下:
一、硬件连接:
软件代码:
#include <SPI.h>
//L99H92 控制口
const int EN_PIN = D2; //D2
const int DIAGN_PIN = D3;
const int DIR_PIN = D4;
const int MTPWM_PIN = D5;
const int FSINB_PIN = D6;
//CS 片选
const int CS_PIN = D10;
void setup() {
//SPI.begin();
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
//串口配置
Serial.begin(115200);
Serial.println("UART Start");
// 设置输入和输出方式
pinMode(CS_PIN,OUTPUT);
pinMode(EN_PIN,OUTPUT);
pinMode(DIAGN_PIN,INPUT);
pinMode(DIR_PIN,OUTPUT);
pinMode(MTPWM_PIN,OUTPUT);
pinMode(FSINB_PIN,OUTPUT);
//设置初始化状态
digitalWrite(CS_PIN,HIGH);
digitalWrite(EN_PIN,LOW);
digitalWrite(FSINB_PIN, LOW);
int Vst = digitalRead(DIAGN_PIN);
//analogWrite(MTPWM_PIN,100);
//启用L99H992
digitalWrite(EN_PIN, HIGH);
digitalWrite(FSINB_PIN, HIGH);
}
void loop() {
//DIR=0, PWM=1
digitalWrite(DIR_PIN,LOW);
digitalWrite(MTPWM_PIN,HIGH);
//INPMODE=0, OUTE=1, AFWE=0,FWS=0;
writeRegister(0x00, 0x03, 0x00,0x40 );
delay(5000);
}
//Sends a write command to L99H92
void writeRegister(uint8_t chipOP,uint8_t chipAddr, uint8_t Value1, uint8_t Value2) {
// take the chip select low to select the device:
digitalWrite(CS_PIN, LOW);
SPI.transfer((chipOP<<6) | chipAddr );
SPI.transfer(Value1);
SPI.transfer(Value2);
// take the chip select high to de-select:
digitalWrite(CS_PIN, HIGH);
}
//Read from or write to register from the L99h92:
uint16_t readRegister_2Byte(uint8_t chipOP,uint8_t chipAddr) {
uint16_t result;
uint8_t date1, date2;
uint8_t first = chipOP<<6;
digitalWrite(CS_PIN, LOW);
// send the device the register you want to read:
SPI.transfer(first | chipAddr);
// send a value of 0 to read the first byte returned:
date1 = SPI.transfer(0x00);
date2 = SPI.transfer(0x00);
// take the chip select high to de-select:
digitalWrite(CS_PIN, HIGH);
// return the result:
result = (date1<<8) | date2;
return result;
}
测试硬件:
测试波形:
操作控制寄存器0x03;
读取状态寄存器GSB;
有个疑问GSB的寄存器地址是0x3E? 还是其他;
SDO 的输出,是opcode(2bit,01时候)+Address(6bit)+GSB(8bit)+data2+data1 ? 是这样?
其他问题正在确认中,
最终结果:
电机没有反应(电机在12V 其他板子测试正常);
请大家帮忙建议下;