Jump to content

Ben Delarre

Members
  • Content Count

    4
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Ben Delarre

  • Rank
    Newbrie
  1. Hi all, Just been working on a PIC18F26J50 project, and have been scratching my head trying to figure out why the chip would not boot up. Turns out it was in debug mode the whole time, so I went to use the new configuration option style to set the debug config bit and found that the debug field is missing from the .tdf for this family of devices. Here's the fix, just add this block to your PIC18F26J50.tdf, PIC18F24J50.tdf, PIC18F46J50.tdf and any other pic in that family (they all appear to be missing this config option). CODE TargetConfig DEBUG{ ConfigRegAddr = 0x0000FFF8; ConfigBitMask = 0b10000000; ConfigSettings = 0b10000000, "OFF","Disabled", 0b00000000, "ON","Enabled"; } Hope that helps save someone some time.
  2. Well, I tried altering the code so that the template definitions match up for the I2C driver, but this hasn't fixed anything unfortunately. Still none the wiser. Can anyone else offer some insight?
  3. Hmmm, yes you could be right there, I'll check these mappings again and make sure they all match up. Perhaps I should go find myself a PIC with hardware I2C.
  4. Hi all, I've been trying to use the I2C software driver to communicate with a MAXIM MAX6964 17 Output LED Driver chip and have tried everything I can think of and am still not having any luck. I've built a simple test circuit with one debug LED and one LED to be driven by the MAX6964. The code appears to run fine on the PIC, I get all the debug blinks I would be expecting so I know the code isn't stalling anywhere. Unfortunately I don't have an in circuit debugger or an oscilloscope, and I haven't yet been able to step through the I2C code in the SourceBoost debugger without getting stuck waiting on a response, so I'm running out of ways I can test this. If anyone has any suggestions as to whats wrong, please let me know as I'm tearing my hair out. The commands I've tried to send to the LED driver are taken from the end of this article with the address byte altered for my grounded AD0 pin. I know this isn't a support forum for the MAXIM chip but I'm not entirely certain I'm setting up my PIC correctly for the I2C software driver and so can't be certain my commands are reaching the LED driver. Any help or suggestions on how I can further debug this would be most appreciated. Thanks -- Ben MAX6964 DataSheet PIC16F684 DataSheet The circuit looks like the following.... And here's the code i've flashed to the PIC16F684 #include <system.h> #include <stdlib.h> #include <string.h> #include <i2c_driver.h> #pragma DATA _CONFIG, _WDT_OFF & _INTOSCIO & _MCLRE_OFF & _BOD_OFF //& _HS_OSC #pragma CLOCK_FREQ 8000000 #define I2c_divisor 0x09 #define use_i2c_SW #if defined use_i2c_SW //////////////////////////////////////////////////////////////////////////// // i2c software implementation template arguments and variables //////////////////////////////////////////////////////////////////////////// #define i2c_ARGS 3, PORTC, TRISC, 4, PORTC, TRISC, e_SSPCON1, e_SSPCON2, \ e_SSPSTAT, e_SSPBUF, e_SSPIF_BIT, e_SSPIF_PIR, \ e_BCLIF_BIT, e_BCLIF_PIR, 7, e_SSPADD, (i2c_reset_wdt | i2c_SMP) // RAM used by the software i2c driver to emulate the equivalent i2c hardware registers unsigned short swi2c_SSPCON1@0x40; // define location for the emulated SSPCON1 unsigned short swi2c_SSPCON2@0x41; // define location for the emulated SSPCON2 unsigned short swi2c_SSPSTAT@0x42; // define location for the emulated SSPSTAT unsigned short swi2c_SSPBUF@0x43; // define location for the emulated SSPBUF unsigned short swi2c_SSPIF_PIR@0x44;// define location for the emulated SSPIF_PIR unsigned short swi2c_BCLIF_PIR@0x45;// define location for the emulated BCLIF_PIR unsigned short swi2c_SSPADD@0x46; // define location for the emulated SSPADD // variables cannot be passed as template arguments. The following constants map to // the PIC registers and software emalated i2c RAM locations. These constants are // then used by the templated functions. When changing the address of an emulated // register the corresponding constant mapping must also be changed. #define e_SSPCON1 0x40 #define e_SSPCON2 0x41 #define e_SSPSTAT 0x42 #define e_SSPADD 0x43 #define e_SSPBUF 0x44 #define e_SSPIF_PIR 0x45 #define e_BCLIF_PIR 0x46 #define e_SSPIF_BIT 3 #define e_BCLIF_BIT 3 #endif #define SLAVE_ADDR 0x20 void blink_on() { char address = SLAVE_ADDR; address <<= 0x01; address &= 0xFE; i2c_start(); i2c_write(address); i2c_write(0x0F); i2c_write(0x0D); i2c_stop(); } void blink_off() { char address = SLAVE_ADDR; address <<= 0x01; address &= 0xFE; i2c_start(); i2c_write(address); i2c_write(0x0F); i2c_write(0x0F); i2c_stop(); } void blinker() { char address = SLAVE_ADDR; address <<= 0x01; address &= 0xFE; i2c_start(); i2c_write(address); i2c_write(0x02); i2c_write(0x00); i2c_write(0x00); i2c_stop(); i2c_start(); i2c_write(address); i2c_write(0x0E); i2c_write(0xF0); i2c_stop(); i2c_start(); i2c_write(address); i2c_write(0x0F); i2c_write(0x0D); i2c_stop(); } void main() { char i_counter; osccon = 0b01110101; // 8mhz INTOSC for system clock while (osccon.2==0); // setup ports porta = 0; trisa = 0; portc = 0; trisc = 0; cmcon0 = 0b00000111; // Turn off Comparators, CxIN pins are digital IO adcon0 = 0b00000001; // Turn off ADC Enable bit ansel = 0b00000000; // Analog Select pins as digital IO (0) ccp1con = 0x00000000; // Switch the comparator unit off // flicker debug LED to show the RESET/REBOOT for ( i_counter = 0; i_counter < 5; i_counter++ ) { porta.0 = 0; delay_ms(50); porta.0 = 1; delay_ms(50); } clear_bit(porta , 0); // I2C Communications #define I2C_divisor 0x7E i2c_init(I2C_divisor); // blink debug led to show init complete porta.0 = 0; delay_ms(500); porta.0 = 1; delay_ms(500); porta.0 = 0; blinker(); while(1) { // turn off all LEDs delay_s(1); blink_off(); // debug blink porta.0 = 0; delay_ms(500); porta.0 = 1; delay_ms(500); porta.0 = 0; // turn on all LEDs delay_s(1); blink_on(); // debug blink porta.0 = 0; delay_ms(500); porta.0 = 1; delay_ms(500); porta.0 = 0; } }
×
×
  • Create New...