bucovigo
26.02.2009, 23:36
Hallo zusammen!!
Ich spreche nicht viel deutsch, und ich denke, es ist besser wenn ich auf englisch schreibe. Tut mir leid!! :P
I hope someone can help me... I´m working with a microcontroller RN-Motorcontrol joined to RN-VNH2 Dualmotor, for controlling a motor of a robot with PWM.
For sending the speed reference values to the RN-Motorcontrol, I use another micro (Infineon C167) which by i2c sends messages using this code in c:
void I2C_SendSRF02Data2(unsigned char slaveid, unsigned char init, unsigned char data1, unsigned char data2)
{
I2CStart();
I2CMasterWrite(slaveid);
I2CMasterWrite(init);
I2CMasterWrite(data1);
I2CMasterWrite(data2);
I2CStop();
Delay(I2C_DELAY*10);
}
Here I put the code of each function. The i2c configuration and all the routines have been used with another infra-red sensor by i2c too, so I think these routines are not the problem...
void I2CStart()
{
Delay(I2C_DELAY);
SDA = 1; /* to make sure the SDA and SCL are both high */
SCL = 1;
Delay(I2C_DELAY);
SDA = 0; /* SDA line go LOW first */
Delay(I2C_DELAY);
SCL = 0; /* then followed by SCL line with time delay */
}
unsigned char I2CMasterWrite(unsigned char input_byte)
{
unsigned char mask,i;
mask = 0x80; /* mask to send a byte*/
/* BYTE SENDING ROUTINE */
for (i=0; i<8; i++)
{
if (mask & input_byte) SDA = 1; /* send bit according to data */
else SDA = 0;
mask >>= 1; /* shift right for the next bit */
I2CClock();
}
/* GENERATE THE 9th PULSE AND WAIT FOR ACKNOWLEDGE */
D_SDA = 0;
I2CClock();
mask = SDA;
D_SDA = 1; /* configure SDA as an Output */
return (mask);
}
void I2CStop( void )
{
SDA = 0;
SCL = 1;
Delay(I2C_DELAY);
SDA = 1;
Delay(I2C_DELAY);
SCL = 0;
SDA = 0;
}
Each Delay (I2C_DELAY) is aprox. 155us
I have analyzed the SDA and the SCL lines with the osciloscope and the values of the line SDA when SCL is in a high level are:
10 (Start)
Byte 1
0 (aknowledge bit)
Byte 2
0 (aknowledge bit)
.........
Byte 4
0 (aknowledge bit)
01 (Stop)
I think these are the correct values for establishing a communication between both micros, so I don´t think this is the problem.
I have used too a program given with the microcontroller, that by RS232 makes the micro work. The motor that I have to make work is the number 2, and I use this number also in i2c.
Sooo..... I think the problem is with the format of the messages. For example, for establishing a speed 100 for the motor 2, the following codes have to be used (text from the microcontroller manual):
RS-232–Syntax in Basic: Print "##";chr(3);chr(2);chr(2);chr(100)
I2C-Syntax in Basic:
I2cstart
I2cwbyte slaveid
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 2 'Motorwahl
I2cwbyte 100 'Geschwindigkeit
I2cstop
I have to program in C, and I´m sending the same parameters than in Basic (slaveid, 35, 2, 1, 100), and the RN-Motorcontrol doesn´t make anything. I have used also the direction 0x00 (for all the slaves in i2c) because maybe the direction is not right, but it doesn´t work.
So I need the help of someone who has worked with this micro, because i have been probing all the combinations of parameters (hexadecimal, integer), one or two bytes "#" in the beginning.... and I don´t know what more can I do. I think if he tells me the value of the correct parameters or the code he is using with C and i2c, it would be great :-)
I thank a lot the person who is able to help me, because I have wasted a lot of time in this stuff!!!!! :S
Danke schön :-)
I edit for saying that the microcontroller works with CRC8. In the program I have spoken about, without this mode it didn´t work. So in i2c I have to activate it first this mode with one message, and then I send each message (for establishing the speed, for example) with the CRC8 in the end of the message. I have probed also sending messages with CRC8, without CRC8, etc.... and it doesn´t work
Ich spreche nicht viel deutsch, und ich denke, es ist besser wenn ich auf englisch schreibe. Tut mir leid!! :P
I hope someone can help me... I´m working with a microcontroller RN-Motorcontrol joined to RN-VNH2 Dualmotor, for controlling a motor of a robot with PWM.
For sending the speed reference values to the RN-Motorcontrol, I use another micro (Infineon C167) which by i2c sends messages using this code in c:
void I2C_SendSRF02Data2(unsigned char slaveid, unsigned char init, unsigned char data1, unsigned char data2)
{
I2CStart();
I2CMasterWrite(slaveid);
I2CMasterWrite(init);
I2CMasterWrite(data1);
I2CMasterWrite(data2);
I2CStop();
Delay(I2C_DELAY*10);
}
Here I put the code of each function. The i2c configuration and all the routines have been used with another infra-red sensor by i2c too, so I think these routines are not the problem...
void I2CStart()
{
Delay(I2C_DELAY);
SDA = 1; /* to make sure the SDA and SCL are both high */
SCL = 1;
Delay(I2C_DELAY);
SDA = 0; /* SDA line go LOW first */
Delay(I2C_DELAY);
SCL = 0; /* then followed by SCL line with time delay */
}
unsigned char I2CMasterWrite(unsigned char input_byte)
{
unsigned char mask,i;
mask = 0x80; /* mask to send a byte*/
/* BYTE SENDING ROUTINE */
for (i=0; i<8; i++)
{
if (mask & input_byte) SDA = 1; /* send bit according to data */
else SDA = 0;
mask >>= 1; /* shift right for the next bit */
I2CClock();
}
/* GENERATE THE 9th PULSE AND WAIT FOR ACKNOWLEDGE */
D_SDA = 0;
I2CClock();
mask = SDA;
D_SDA = 1; /* configure SDA as an Output */
return (mask);
}
void I2CStop( void )
{
SDA = 0;
SCL = 1;
Delay(I2C_DELAY);
SDA = 1;
Delay(I2C_DELAY);
SCL = 0;
SDA = 0;
}
Each Delay (I2C_DELAY) is aprox. 155us
I have analyzed the SDA and the SCL lines with the osciloscope and the values of the line SDA when SCL is in a high level are:
10 (Start)
Byte 1
0 (aknowledge bit)
Byte 2
0 (aknowledge bit)
.........
Byte 4
0 (aknowledge bit)
01 (Stop)
I think these are the correct values for establishing a communication between both micros, so I don´t think this is the problem.
I have used too a program given with the microcontroller, that by RS232 makes the micro work. The motor that I have to make work is the number 2, and I use this number also in i2c.
Sooo..... I think the problem is with the format of the messages. For example, for establishing a speed 100 for the motor 2, the following codes have to be used (text from the microcontroller manual):
RS-232–Syntax in Basic: Print "##";chr(3);chr(2);chr(2);chr(100)
I2C-Syntax in Basic:
I2cstart
I2cwbyte slaveid
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 2 'Motorwahl
I2cwbyte 100 'Geschwindigkeit
I2cstop
I have to program in C, and I´m sending the same parameters than in Basic (slaveid, 35, 2, 1, 100), and the RN-Motorcontrol doesn´t make anything. I have used also the direction 0x00 (for all the slaves in i2c) because maybe the direction is not right, but it doesn´t work.
So I need the help of someone who has worked with this micro, because i have been probing all the combinations of parameters (hexadecimal, integer), one or two bytes "#" in the beginning.... and I don´t know what more can I do. I think if he tells me the value of the correct parameters or the code he is using with C and i2c, it would be great :-)
I thank a lot the person who is able to help me, because I have wasted a lot of time in this stuff!!!!! :S
Danke schön :-)
I edit for saying that the microcontroller works with CRC8. In the program I have spoken about, without this mode it didn´t work. So in i2c I have to activate it first this mode with one message, and then I send each message (for establishing the speed, for example) with the CRC8 in the end of the message. I have probed also sending messages with CRC8, without CRC8, etc.... and it doesn´t work