Other Parts Discussed in Thread: , MSP430G2553
Hello,
Regarding to the supply voltage register(Reg:0x1A) on DRV10983 ,my customer is asking some question.
(Question)
(1) This register is supported only during motor operation.
My understanding is correct?
Because It is described on sample code in target board( DRV10983EVM-TB).
But the motor is not operated on this board ,and it recommends motor stopping at EEPROM programming.
So, I’m asking that just in case.
(2) If it is not supported during motor stopping, do you have anything good idea for monitoring supply voltage(>22v) at EEPROM programming?
(I don’t know the behavior of other motor on default EEPROM value.)
Regards,
Tao2199
/*
* I2C_MSP430G2553.c
*
* This file contains the software I2C used to configure the DRV10983 or
* DRV10975. It is designed to be used with the MSP430G2553 LaunchPad and
* programming socket board.
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#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);
}