Hello,
If I understand correctly, the software is working.
Lets try something.
You will still need the terminal program for this test.
The test will use servo 1 and servo 3
Try the code below and let me know what the Servos are doing and if the terminal program displays:
********************
* No ACK from SD20 *
********************
Greetings,
Drifter2006
Code:'**************** I/O PORTS ****************' define sda port[7] define scl port[8] '*******************************************' '**************** A/D PORTS ****************' '*******************************************' '**************** D/A PORTS ****************' '*******************************************' '**************** VARIABLES ****************' define control_flags byte[1] define i2c_nack bit[1] define i2c_last bit[2] define i2c_nack_count byte[2] define i2c_byte byte[3] define i2c_out_bit bit[24] define i2c_in_bit bit[17] define i2c_loop byte[4] define servo_number byte[5] define servo_position byte[6] '*******************************************' '**************** CONSTANTS ****************' define sd20_i2c_address 194 '*******************************************' '****************** SETUP ******************' '*******************************************' '***************** PROGRAM *****************' #start servo_number = 1 servo_position = 255 gosub sd20_servo_driver servo_number = 3 servo_position = 255 gosub sd20_servo_driver servo_number = 1 servo_position = 1 gosub sd20_servo_driver servo_number = 3 servo_position = 1 gosub sd20_servo_driver goto start '*******************************************' '*************** SUBROUTINES ***************' #sd20_servo_driver gosub start_i2c i2c_byte = sd20_i2c_address : gosub write_byte_i2c i2c_byte = servo_number : gosub write_byte_i2c i2c_byte = servo_position : gosub write_byte_i2c gosub stop_i2c if i2c_nack_count > 9 then goto no_ack_from_sd20 if i2c_nack then goto sd20_servo_driver return #start_i2c sda = 0 : scl = 0 return #stop_i2c sda = 0 : deact scl : deact sda return #write_byte_i2c for i2c_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 goto i2c_error i2c_nack_count = 0 return #i2c_error i2c_nack_count = i2c_nack_count + 1 goto stop_i2c #read_byte_i2c i2c_last = 0 #get_i2c_byte deact sda for i2c_loop = 1 to 8 deact scl #read_byte_i2c_clock_stretch if not scl then goto read_byte_i2c_clock_stretch i2c_in_bit = sda scl = 0 if i2c_loop < 8 then i2c_byte = i2c_byte shl 1 next if i2c_last then deact sda else sda = 0 deact scl #read_byte_i2c_ack_clock_stretch if not scl then goto read_byte_i2c_ack_clock_stretch scl = 0 return #read_last_byte_i2c i2c_last = 1 goto get_i2c_byte '*******************************************' '******* INITIALIZATION SUBROUTINES ********' '*******************************************' '********* CALIBRATION SUBROUTINES *********' '*******************************************' '****************** DATA *******************' '*******************************************' '************* ERROR MESSAGES **************' #no_ack_from_sd20 print"********************" print"* No ACK from SD20 *" print"********************" pause 50 return '*******************************************'







Zitieren

Lesezeichen