
|
INFO - FAQ - CC2-Forum - CCPro-Forum |
|
Hello, I dont know this motor driver but maybe this will help you. Greetings, H.J. Windt '****************** PORTS ******************' define sda port[1] define scl port[2] '*******************************************' '**************** VARIABLES ****************' define i2c_nack bit[7] define i2c_error_count byte[2] define i2c_byte byte[3] define i2c_out_bit bit[24] define loop byte[4] '*******************************************' '**************** CONSTANTS ****************' define max_number_of_i2c_errors 4 '*******************************************' '****************** SETUP ******************' i2c_error_count = 0 '*******************************************' '***************** PROGRAM *****************' #one gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c if i2c_nack then goto pass_one i2c_byte = 10 : gosub write_byte_i2c if i2c_nack then goto pass_one i2c_byte = 1 : gosub write_byte_i2c if i2c_nack then goto pass_one i2c_byte = 2 : gosub write_byte_i2c if i2c_nack then goto pass_one i2c_byte = 50 : gosub write_byte_i2c if i2c_nack then goto pass_one i2c_byte = 0 : gosub write_byte_i2c #pass_one gosub stop_i2c if i2c_error_count >= max_number_of_i2c_errors then goto no_ack_from_i2c_device if i2c_nack then goto one i2c_error_count = 0 #two gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c if i2c_nack then goto pass_two i2c_byte = 10 : gosub write_byte_i2c if i2c_nack then goto pass_two i2c_byte = 14 : gosub write_byte_i2c if i2c_nack then goto pass_two i2c_byte = 0 : gosub write_byte_i2c if i2c_nack then goto pass_two i2c_byte = 0 : gosub write_byte_i2c if i2c_nack then goto pass_two i2c_byte = 0 : gosub write_byte_i2c #pass_two gosub stop_i2c if i2c_error_count >= max_number_of_i2c_errors then goto no_ack_from_i2c_device if i2c_nack then goto two i2c_error_count = 0 #three gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c if i2c_nack then goto pass_three i2c_byte = 10 : gosub write_byte_i2c if i2c_nack then goto pass_three i2c_byte = 4 : gosub write_byte_i2c if i2c_nack then goto pass_three i2c_byte = 2 : gosub write_byte_i2c if i2c_nack then goto pass_three i2c_byte = 1 : gosub write_byte_i2c if i2c_nack then goto pass_three i2c_byte = 0 : gosub write_byte_i2c #pass_three gosub stop_i2c if i2c_error_count >= max_number_of_i2c_errors then goto no_ack_from_i2c_device if i2c_nack then goto three i2c_error_count = 0 #four gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c if i2c_nack then goto pass_four i2c_byte = 10 : gosub write_byte_i2c if i2c_nack then goto pass_four i2c_byte = 8 : gosub write_byte_i2c if i2c_nack then goto pass_four i2c_byte = 2 : gosub write_byte_i2c if i2c_nack then goto pass_four i2c_byte = 100 : gosub write_byte_i2c if i2c_nack then goto pass_four i2c_byte = 0 : gosub write_byte_i2c #pass_four gosub stop_i2c if i2c_error_count >= max_number_of_i2c_errors then goto no_ack_from_i2c_device if i2c_nack then goto four i2c_error_count = 0 #five gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c if i2c_nack then goto pass_five i2c_byte = 10 : gosub write_byte_i2c if i2c_nack then goto pass_five i2c_byte = 6 : gosub write_byte_i2c if i2c_nack then goto pass_five i2c_byte = 2 : gosub write_byte_i2c if i2c_nack then goto pass_five i2c_byte = 0 : gosub write_byte_i2c if i2c_nack then goto pass_five i2c_byte = 0 : gosub write_byte_i2c #pass_five gosub stop_i2c if i2c_error_count >= max_number_of_i2c_errors then goto no_ack_from_i2c_device if i2c_nack then goto five i2c_error_count = 0 end '*******************************************' '*************** SUBROUTINES ***************' #no_ack_from_i2c_device print"**************************" print"* No ACK from I2C device *" print"**************************" pause 50 goto no_ack_from_i2c_device #start_i2c sda = 0 : scl = 0 return #stop_i2c sda = 0 : deact scl : deact sda return #write_byte_i2c for loop = 1 to 8 sda = i2c_out_bit deact scl #write_byte_i2c_clock_stretch if not scl then goto write_byte_i2c_clock_stretch scl = 0 i2c_byte = i2c_byte shl 1 next deact sda deact scl #write_byte_i2c_ack_clock_stretch if not scl then goto write_byte_i2c_ack_clock_stretch i2c_nack = sda scl = 0 if i2c_nack then i2c_error_count = i2c_error_count + 1 return '*******************************************' '******* INITIALIZATION SUBROUTINES ********' '*******************************************' '****************** DATA *******************' '*******************************************' > > Hallo an Alle, > > ich habe das Problem eine Routine für den Motortreiber "RN-Motor i2c" zu schreiben. > Seit mehreren Tagen versuche ich das Ding zum laufen zu bringen. > > Bitte !!! kann mir Jemand sagen was ich da falsch mache. > > Am Besten währe es, wenn ich ein Programmbeispiel bekommen könnte. > > Danke Rille > > define sda port[1] > define scl port[2] > define daten byte > define n byte > > sda = on > scl = on > > gosub start > daten = &H56 > gosub i2c_write > daten = 10 'kennung > gosub i2c_write > daten = 1 'befehlscod > gosub i2c_write > daten = 2 'motor > gosub i2c_write > daten = 50 > gosub i2c_write > daten = 0 > gosub i2c_write > gosub stop > > gosub start > daten = &H56 > gosub i2c_write > daten = 10 'kennung > gosub i2c_write > daten = 14 'befehlscod > gosub i2c_write > daten = 0 'motor > gosub i2c_write > daten = 0 > gosub i2c_write > daten = 0 > gosub i2c_write > gosub stop > > gosub start > daten = &H56 > gosub i2c_write > daten = 10 'kennung > gosub i2c_write > daten = 4 'befehlscod > gosub i2c_write > daten = 2 'motor > gosub i2c_write > daten = 1 > gosub i2c_write > daten = 0 > gosub i2c_write > gosub stop > > gosub start > daten = &H56 > gosub i2c_write > daten = 10 'kennung > gosub i2c_write > daten = 8 'befehlscod > gosub i2c_write > daten = 2 'motor > gosub i2c_write > daten = 100 > gosub i2c_write > daten = 0 > gosub i2c_write > gosub stop > > gosub start > daten = &H56 > gosub i2c_write > daten = 10 'kennung > gosub i2c_write > daten = 6 'befehlscod > gosub i2c_write > daten = 2 'motor > gosub i2c_write > daten = 0 > gosub i2c_write > daten = 0 > gosub i2c_write > gosub stop > > end > > #i2c_write > for n = 1 to 8 > sda = off > if (daten and 128) = 128 then sda = on > pulse scl > daten = daten shl 1 > next > pulse scl > return > > #start > sda = off > scl = off > return > > #stop > sda = off > scl = on > sda = on > return > > > > > |
| Antwort schreiben |