CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ADXL 345 and 18F66K22 NO WORKING ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Cogitum



Joined: 22 Mar 2012
Posts: 70
Location: France (Paris)

View user's profile Send private message

ADXL 345 and 18F66K22 NO WORKING ?
PostPosted: Tue Nov 17, 2015 9:55 pm     Reply with quote

Embarassed

Hi,
The hardware I use is operating normally.
ADXL345 generates X, Y and Z with another program and I get to do what I want. This is not the case with the program below.
I want to generate a "pulse" to generate an interrupt (thereafter) but program generates signals of 0V and 3V for 200 for 700 uS

The pin 8 of ADXL345 is connected to pin 48 of 18F66K22 with a pull up R 10K.

COMPILER VERS 4.132

Code:
#include <18F66K22.h>                                                                         
#device adc=12                                                           
                                                   
                                                                               
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale                 
//#FUSES INTRC                    //Internal RC Osc
#FUSES NOBROWNOUT               //No brownout reset
//#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O   
#FUSES HSH                     //High speed Osc, high power 16MHz-25MHz
#FUSES BBSIZ1K                  //1K words Boot Block size
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode) 


#use delay(crystal=20M)
//!#use delay(clock=20000000)       
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)                         
                                                       
#include <stdio.h>
#include <string.h>             
#include <stdlib.h>       
#include <math.h>                                                                                                                 

#define ACCEL_WRITE_ADDR   0XA6
#define ACCEL_READ_ADDR    0XA7
#define ACCEL_DATA_ADDR    0x32
#define ACCEL_PWRCTRL_ADDR 0x2d
#define ACCEL_MEASURE_MODE 0x08

#define ACCEL_THRESH_TAP   0x1D
#define ACCEL_TAP_AXES     0x2A
#define ACCEL_LATENT       0x22
#define ACCEL_WINDOWS      0x23
#define ACCEL_DURATION     0x21

#define ACCEL_INT_ENABLE   0x2E
#define ACCEL_INT_MAP      0x2F
#define ACCEL_INT_SOURCE   0x30
#define ACCEL_DATA_FORMAT  0x31
                                               

void main()   
{                             


printf ("START TEST \r\n"); 
while(TRUE)   
{                                         
 output_high(pin_G0);                                                                                           
// Tell the accelerometer to wake up
 i2c_start();
 i2c_write(ACCEL_WRITE_ADDR);
 i2c_write(0X31);
//! i2c_write(0X00);//    init register (scale)                             
 i2c_write(0X3);//
 i2c_stop();                                   

I2C_start();                                                         
i2c_write(ACCEL_WRITE_ADDR); 
i2c_write(ACCEL_PWRCTRL_ADDR);
i2c_write(0x08);
i2c_write(ACCEL_MEASURE_MODE); 
i2c_write(ACCEL_LATENT);
i2c_write(0x50);
//!i2c_write(0x50);
i2c_write(ACCEL_WINDOWS);
i2c_write(0xFF);
i2c_write(ACCEL_DURATION);
i2c_write(0x1F);
i2c_write(ACCEL_TAP_AXES);
i2c_write(0x7);

i2c_write(ACCEL_THRESH_TAP);
i2c_write(48);
i2c_write(ACCEL_INT_SOURCE);
i2c_write(0x01);
i2c_write(ACCEL_DATA_FORMAT);
i2c_write(0x01);


i2c_write(ACCEL_INT_ENABLE);
i2c_write(0x90);

i2c_write(ACCEL_INT_MAP);
i2c_write(0x80);

I2C_stop();

 output_low(pin_G0);
}
}

Thank for your HELP
guy



Joined: 21 Oct 2005
Posts: 297

View user's profile Send private message Visit poster's website

PostPosted: Sat Nov 21, 2015 7:00 am     Reply with quote

assuming you are programming the ADXL correctly it will generate an active-high interrupt pulse of 3V because it works on ~3V. To receive this in the 5V PIC you can do either:
1. Connect the signal to the pic's COMPARATOR and set a voltage reference of <3V. This will cause a comparator interrupt.
2. Connect the signal through a resistor to the base of a transistor, and then use your existing 5V pull-up resistor for the output. This will convert the signal from 3V to 5V but it will also INVERT it. Normally it would be high, and fall when interrupt is received.
Does this help?
temtronic



Joined: 01 Jul 2010
Posts: 9218
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 21, 2015 9:59 am     Reply with quote

'Classic' 5 volt PIC and 3 volt peripheral ?

options include
1) using a 3 volt rated PIC ( 'L' versions )

2) logic level converters between PIC and peripheral


1 is easy , 2 means more parts, chance of miswiring

Jay
guy



Joined: 21 Oct 2005
Posts: 297

View user's profile Send private message Visit poster's website

PostPosted: Sat Nov 21, 2015 10:12 am     Reply with quote

The I2C can work on 3V pull-up resistors and then the only interface missing is the INT pins.
Ttelmah



Joined: 11 Mar 2010
Posts: 19482

View user's profile Send private message

PostPosted: Sat Nov 21, 2015 10:19 am     Reply with quote

SMBUS.

You need to have pull-ups to 3.3v, and set PIC I2C to use SMBUS (this is an option in #USE I2C).

On chips that support SMBUS (this one does), it'll then reprogram the PIC I/O levels to accept the required inputs. Without this, the PIC will not see the bus as going high enough.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group