PDA

View Full Version : I2C Communication from 18F4PIC550 to Titan Intel BLDC Motor Driver



JJVector
- 7th August 2012, 10:07
Hi,

Quick note to apologise for if I miss any information out from this initial post, if you ask for any more information i'll post it as soon as I can. I have hunted the forums on this and every other site to find a answer but to no avail.

Objective
Read PelcoP control command from a serial port and output the correct I2C control commands to the Titan Intelligent BLDC Motor along the SDA line asynchronously. This must be completed using Pic Basic Pro.

Progress
I started from the working C code that was given to me by the previous person assigned to the project. This C code works absolutely fine and reads the commands in and write the I2C commands out perfectly (although the code is badly written). The code can be seen here.
I slowly worked through using PicBasic with the PIC18F4550 to get it to flash the on-PCB led to test my programmer and code works correctly, which it does and then moved on to try to create a simple program that writes the I2C commands straight from code to the motor driver. This is where I got stuck and have remained stuck for a number of days. I need you help to get this program writing the commands to the motor dirver to get it to move.

Resources
Original C Code: 6622 (Apologies about the write up, you will need to copy and paste it into a editor like notepad++ and set language to C)
Titan BLDC Motor I2C Protocol (http://www.overview.co.uk/pdfs/bldc_i2c_doc_V1.2.15.pdf)
PIC18F4550 Datasheet (http://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf)
The PicBasic code I am trying to get to work: 6621

Relevant Information

The SDA line is connected to PORTB.0
The SCL line is connected to PORTB.1
The clock used is the 8MHz internal clock set by OSCCON = 110010
I can see the output from the PIC trying to write to the camera but the camera remains stationary. It seems the output is working but the motor driver is not reading the data in.
The SDA output from the C code and the PBP code seem to be the same.
The SCL line on both programs remains high throughout the code process.
The configuration bits set in the PBP file is there to make it match the C code config bits.
Thanks for your help, replies e.t.c.

JJVector
- 7th August 2012, 10:42
The clock used is the 8MHz internal clock set by OSCCON = 110010

Edit: OSCCON = %01110010

JJVector
- 7th August 2012, 16:16
PanRightNormal:
PORTB = $1C 'STX Set Ports Low
addr = $00 'Set address to write to to default (0)
a[0] = $07
a[1] = $00
a[2] = $00
'gosub flashled 'Flash debug LED on PortE
pause 10 'Pause 10ms between commands to allow them to go through
I2CWRITE sda,scl,cont,[STR a\3] 'Write 0101|000|0 to initialise I2C comms (controlbyte|address|read/write)
'LSB of velocity byte
'gosub flashled 'Flash debug LED to show commandds ave been completed
pause 10 'Pause 0.01 second
return


Using a array fixed my problem, i was continually sending the control byte when did it separately.