TI中文支持网
TI专业的中文技术问题搜集分享网站

msp430 usb 多次发送死机的情况

我在使用MSP430 的usb 的时候发现在使用以下代码的时候  用 HidDemo.jar   多次发送 ENCM  !后 HID demo.jar 就不在响应命令 ,430 单片机也不在接收数据!想问一下这是怎么回事 ?如果我多次执行一个命令!该怎么样!现在多次执行者一个,命令就会死机!

void main (void)
{
WDT_A_hold(WDT_A_BASE); // Stop watchdog timer

#ifndef DRIVERLIB_LEGACY_MODE
PMM_setVCore(PMM_CORE_LEVEL_2);

#else
PMM_setVCore(PMM_BASE, PMM_CORE_LEVEL_2);
#endif

initPorts(); // Config GPIOS for low-power (output low)
initClocks(16000000); // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz

// initTimer(); // Prepare timer for LED toggling
// initRTC();

// initAdc_as_transmit();
initRTC();
initAdc();
//send it must sure 5529 on traverate mode
USB_setup(TRUE, TRUE); // Init USB & events; if a host is present, connect
__enable_interrupt(); // Enable interrupts globally
while (1)
{
uint8_t i;
switch (USB_connectionState()) // Check the USB state and directly main loop accordingly
{
// This case is executed while your device is enumerated on the USB host
case ST_ENUM_ACTIVE:
// Enter LPM0 (can't do LPM3 when active)
__bis_SR_register(LPM0_bits + GIE);
_NOP();if (bHIDDataReceived_event)
{
char pieceOfString[MAX_STR_LENGTH] = ""; // Holds the new addition to the string
char outString[MAX_STR_LENGTH] = ""; // Holds the outgoing string
char data[MAX_STR_LENGTH] = "";hidReceiveDataInBuffer((uint8_t*)pieceOfString, MAX_STR_LENGTH,HID0_INTFNUM); // Get the next piece of the string
strcat(wholeString,pieceOfString); // Append new piece to the whole

if (retInString(wholeString)){ // Has the user pressed return yet?

if (!(strcmp(pieceOfString, "ENCM"))) // Compare to string #1, and respond
{

enter_command_mode(); //enter cm mode

} else if(!(strcmp(pieceOfString, "ENNR"))){

enter_noramal();

} else if(!(strcmp(pieceOfString, "ENRW"))) {
enter_raw(); //output the raw values of the ADC for the Bridge reading.

}

else {
// Prepare the outgoing string
strcpy(outString,"\r\nNo such command!\r\n\r\n");
// Send the response over USB
hidSendDataInBackground((uint8_t*)outString,
strlen(outString),HID0_INTFNUM,0);
}
// Clear the string in preparation for the next one
for (i = 0; i < MAX_STR_LENGTH; i++){
wholeString[i] = 0x00;
}
}
bHIDDataReceived_event = FALSE;
}
break;

// These cases are executed while your device is disconnected from
// the host (meaning, not enumerated); enumerated but suspended
// by the host, or connected to a powered hub without a USB host
// present.
case ST_PHYS_DISCONNECTED:
case ST_ENUM_SUSPENDED:
case ST_PHYS_CONNECTED_NOENUM_SUSP:
// Turn off LED P1.0
// GPIO_setOutputLowOnPin(LED_PORT, LED_PIN);
__bis_SR_register(LPM3_bits + GIE);
_NOP();
break;

// The default is executed for the momentary state
// ST_ENUM_IN_PROGRESS. Usually, this state only last a few
// seconds. Be sure not to enter LPM3 in this state; USB
// communication is taking place here, and therefore the mode must
// be LPM0 or active-CPU.
case ST_ENUM_IN_PROGRESS:
default:;
}

} //while(1)
} //main()

void Test_IC_Power(bool on)
{
if (on)
P3OUT |= (BIT5+BIT6);
else
P3OUT &=~(BIT5+BIT6);
}

void enter_command_mode(void)
{
static uint32_t display_delay=80000;
static uint16_t power_delay =5000;

while(display_delay–);
Test_IC_Power(false); // Power down it first before we power on // and ask to enter command mode
while(power_delay–);
Test_IC_Power(true);
power_delay = 300;
while(power_delay–);

zac_gpio_out();
zac_send_19bits_packet(0x50, 0x90);
zac_gpio_in_it_falling();

}

static void zac_write_bit(uint8_t bit, bool parity_flag) //0, 1 data bit low and high, others means "Start" bit
{
uint16_t low_delay_counter, high_delay_counter;
if (0 == bit) {
low_delay_counter = 54;
high_delay_counter = 17;
} else if (1 == bit) {
low_delay_counter = 18;
high_delay_counter = 52;
} else {
low_delay_counter = 37; //1170
high_delay_counter =34; //78
}
//GPIO_WriteLow(OWI_PORT, OWI_PIN);
GPIO_setOutputLowOnPin(OWI_PORT, OWI_PIN);
while(low_delay_counter–)
{
__delay_cycles(6); //1US
}
//GPIO_WriteHigh(OWI_PORT, OWI_PIN);
GPIO_setOutputHighOnPin(OWI_PORT, OWI_PIN);
if (!parity_flag) //if 0 run
while(high_delay_counter–){
__delay_cycles(6); //1US
}
}

static void zac_write_byte(uint8_t byte, bool flag)
{
uint8_t i, parity;
parity = 0;
for (i=0; i<8; i++) {
if (byte & 0x80) {
zac_write_bit(1, false);
parity ++;
} else {
zac_write_bit(0, false);
}
byte <<= 1;
}
if (parity&1)
zac_write_bit(1, flag);
else
zac_write_bit(0, flag);
}

void zac_send_19bits_packet(uint8_t cmd, uint8_t dat)
{
// pre_command = ((uint16_t)cmd)<<8 | dat;
zac_write_bit(115, false); // "start bit"
zac_write_byte(cmd, false);
zac_write_byte(dat, true);
}

灰小子:

我觉得可能是上位机HidDemo.jar 的问题

qigong du:

回复 灰小子:

觉得不起作用,要有事实依据来说明!

赞(0)
未经允许不得转载:TI中文支持网 » msp430 usb 多次发送死机的情况
分享到: 更多 (0)