Hi,
I'm trying to use a stepmotor (PD3-110-42-485) with an MSP430FG4619.
The communication is made with RS485 throught a MAX3486 and it is connected to P4.0/P4.1 pin. The MSP430FG4619 has a 32khz and 8Mhz crystal.
I manage to send command to the stepmotor (the motor rotate) but I have difficulties to get a proper reply.
The initialisation for the uart is :
P4DIR |= (BIT0);
P4DIR &= ~(BIT1);
P4SEL |= BIT0+BIT1;
P6DIR |= (BIT7+BIT6);
P6SEL &= ~(BIT7+BIT6);
RS485_DE(0);
RS485_RE(0);
U1CTL |= SWRST;
// parity='none', stopbits=1, address=1,
// CHAR : bits=8
U1CTL |= CHAR; // 8-bit character
U1TCTL |= SSEL0;
// baud=9600
U1BR0 = 0x03;
U1BR1 = 0x00;
U1MCTL = 0x4A; // Modulation
ME2 &= ~(UTXE1 + URXE1); // Diseable USART1 TXD/RXD
U1CTL &= ~SWRST; // Initialize USART state machine
Since I manage to make the motor move, I don't think there is a problem there.
There communication is made like this :
unsigned long wait;
RS485_DE(1);
RS485_RE(0);
ME2 |= UTXE1; // Enable USART1 TXD
for(int i=0;i<9;i++)
{
moteur.reply.data[i] = 0;
}
moteur.ready = FALSE;
for(int i=0;i<9;i++)
{
while(!(IFG2 & UTXIFG1));
U1TXBUF = moteur.command.data[i];
}
while(!(U1TCTL&TXEPT));
moteur.reply.data[0] = U1RXBUF; // remove possible data in buffer
ME2 &= ~UTXE1; // Diseable USART1 TXD
ME2 |= URXE1; // Eneable USART1 RXD
RS485_DE(0);
RS485_RE(0);
for(int i=0;i<9;i++)
{
wait = 0;
while((!(IFG2 & URXIFG1))&&(wait<0xFFFFF)) { wait++; }
if(wait>=0xFFFFF) { moteur.reply.data[i] = 0; }
else moteur.reply.data[i] = U1RXBUF;
}
ME2 &= ~URXE1; // Diseable USART1 RXD
for(int i=0;i<9;i++)
{
usb_writeByte(moteur.command.data[i]);
usb_write('-');
}
usb_writeStr("\r\n");
for(int i=0;i<9;i++)
{
usb_writeByte(moteur.reply.data[i]);
usb_write(':');
}
usb_writeStr("\r\n");
I'm not sure with the while(!(U1TCTL&TXEPT));
The "usb" is a rs232 communication with a PC to help me to debug (UCA0).
So I got on the PC :
01-09-4B-00-00-00-00-C8-1D-
64:09:00:00:00:C8:38:00:00:
BAD
01-09-4B-00-00-00-00-C8-1D-
64:09:00:00:00:C8:38:00:00:
BAD
01-09-4B-00-00-00-00-C8-1D-
64:09:00:00:00:C8:38:00:00:
BAD
01-09-4B-00-00-00-00-C8-1D-
64:09:00:00:00:C8:38:00:00:
BAD
01-09-4B-00-00-00-00-C8-1D-
64:09:00:00:00:C8:38:00:00:
BAD
01-09-4B-00-00-00-00-C8-1D-
02:01:64:09:00:00:00:C8:38:
OK
01-04-01-00-00-00-4E-20-74-
64:04:00:00:4E:20:D9:00:00:
BAD
01-09-4B-00-00-00-00-C8-1D-
00:00:C8:38:00:00:00:00:00:
BAD
01-04-01-00-FF-FF-B1-E0-95-
64:04:00:00:00:00:6B:00:00:
BAD
01-04-01-00-00-00-4E-20-74-
64:04:00:00:4E:20:D9:00:00:
BAD
The reply should be 01:02:64:XX:XX:XX:XX:XX:XX. So most of the time, I miss 2 bytes and even 4 bytes in some case. The worst is that the first command is to specify a delay between the command and the reply...
Is there a problem on the MSP430 side or should I investigate more on the motor side ?


