MikroC Support 16F18425 MSSP2

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
robertj
Posts: 11
Joined: 15 Oct 2013 01:36

MikroC Support 16F18425 MSSP2

#1 Post by robertj » 08 May 2022 18:35

I am having an odd situation. I have been working on slave code using MSSP1 in a PIC16F18325. The slave code works and now I want MSSP2 to talk to a loadcell. When I initialize MSSP2 and MSSP1 MSSP2 does not function. If I intialize MSSP2 only it works but only after a full erase of the PIC. If MSSP1 is initialized something is set in the PIC that gets remembered after POR and despite being programmed without it in the code the code does not function. Only an erase and then a reprogram will MSSP2 start to function. Another problem is MSSP2 has to be initialized twice to work reliably after a POR.

Anyone run into this. I am thinking a support ticket since this is supported MikroC code


#define Lo(param) ((char *)&param)[0]
#define Hi(param) ((char *)&param)[1]

unsigned short rxbuffer[4];
unsigned short rxi = 1;
unsigned short tx_data[5];
unsigned short txi;
unsigned short j;// just dummy for buffer read
unsigned short I2C1_addr ;
unsigned int avg_cnts = 0 ;
unsigned int force_counts = 0 ;


//unsigned short ADDR = 0xb1;//0b01010001; // set I2C device address28

void main()
{
//I2C1_init(100000); Must be remmed out and chip erased for MSSP2 to work
I2C2_init(100000);
OSCCON1 = 0b00000001; //Set clock to internal PLL 16 mhz
TRISA = 0b11101111; // RA 4 becomes output
TRISC = 0b00110011; //I2C1=RC0,RC1 I2C2=RC4,RC5 SET TO INPUTS
ANSELA = 0b00000000; //Disable other modules Port A
ANSELC = 0b00000000; //Disable other modules Port C
PIE1.B3 = 1; // SSP1IE Enables the MSSP interrupt
SSP1STAT = 0b00000000;
SSP1CON1 = 0b00111110;
SSP1CON2 = 0b00100001;
SSP1CON3 = 0b00000101;

if(porta.b5 == 1) SSP1ADD = 0xb1; // 0x68 0x58 address select
else SSP1ADD = 0xd1;

I2C2_init(100000); //Require twice?
DELAY_MS(50);
I2C2_start(); // Initializes average
I2C2_wr(0x51);
Hi(force_counts) = I2C2_rd(1);
Lo(force_counts) = I2C2_rd(1);
force_counts <<= 1;
Hi(avg_cnts) = I2C2_rd(1);
Lo(avg_cnts) = I2C2_rd(0);
avg_cnts <<= 1;
I2C2_stop();



while (1)
{
porta.b4 = 0 ; //marker pulse
porta.b4 = 1 ;
porta.b4 = 0 ;

porta.b4 = 0 ; //marker pulse
porta.b4 = 1 ;
porta.b4 = 0 ;



I2C2_start(); // start com to load cell
I2C2_wr(0x51); //get counts load cell
Hi(force_counts) = I2C2_rd(1);
Lo(force_counts) = I2C2_rd(0);

force_counts <<= 1; //counts 2x

//compute average based on 100 readings

if (force_counts > avg_cnts) avg_cnts +=(((force_counts - avg_cnts)/100)+1);
else delay_us(96);
if (avg_cnts > force_counts) avg_cnts -=(((avg_cnts - force_counts)/100)+1);
else delay_us(96);

}

robertj
Posts: 11
Joined: 15 Oct 2013 01:36

Re: MikroC Support 16F18425 MSSP2

#2 Post by robertj » 08 May 2022 18:39

Correction Title should read 16F18325

Post Reply

Return to “mikroC PRO for PIC General”