PICcoder.co.uk Forum  


::post new topic::
New to PIC and I2C Help Please
Date: 2007/02/01 16:04 By: Ben Rowe Status: Visitor  
 
Hi there having a problem with this code just trying to get my head arround the pics and the I2C protocol. Im currently using a PIC DEM 2+ board from Microchip with MPLAB and connecting to the onboard I2c temp sensor using the c18 compiler. i get a responce but its always a '.' ?? any ideas
thanks
ben
ps heres the code:

#include <p18f452.h>
#include <usart.h>
#include <i2c.h>

#pragma config WDT = OFF

void main (void)
{
unsigned char x;
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
25 );

OpenI2C(MASTER, SLEW_ON);
StartI2C();
x = getsI2C('1000000b', 10);
putrsUSART(x);
StopI2C();
}
reply | quote

Re:New to PIC and I2C Help Please
Date: 2007/02/20 21:30 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
Hmm, well, apart from checking Baud Rate and such (could you try sending some plain Chars just to check?), I can see that you're using
"putrsUSART" which expects a CONST ROM CHAR *...
You're OTOH passing it a simple char: this is wrong.
You can either use "putcUSART(x);" to send the "hex" number corresponding to what is read from I2C, or convert that number to a string (maybe using printf()" and then use "putsUSART" (note "r" is missing... in fact you'll be using a CHAR * i.e. a string.)
reply | quote

::post new topic::