Communication SPI entre 2 pic 16F88

KHADIJA - 4 juin 2022 à 01:31
Bonjour, j'ai un projet qui est basé sur le microcontrôleur Pic 16F88 dont son principe est le suivant:
Un capteur de température LM35 liée au pic 1 ( maitre ) qui prend la valeur du capteur et il envoie au pic 2 ( esclave) pour afficher cette valeur de température dans l'afficheur LCD.
La communication entre les deux pics est SPI.
J'ai essayé plusieurs fois mais le programme ca marche pas; et je sais pas où le problème.
Merci de m'aider pour trouver le problème.
Voici le programme que j'ai fait du maitre :
void main ()
{
TRISB.b1 = 1;
TRISB.b2 = 0;
TRISB.b4 = 0;
TRISB.b5 = 0;
PORTB.b5 =1;
ADC_Init();
// initilisation SPI
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV16, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_LOW_2_HIGH);
while(1)
{
temp = ADC_Read(0);
PORTB.b5 =0;
SPI1_Write(temp);
PORTB.b5 =1;
delay_ms(500);
}
}
Voici le programme que j'ai fait de l'esclave:
// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;

sbit sck at PORTB.b3;
sbit sck_direction at TRISB.b4;

sbit dt at PORTB.b4;
sbit dt_direction at TRISB.b4;


//outputs
sbit mcw at PORTB.b5;
sbit mcw_direction at TRISB.b5;

sbit mccw at PORTB.b7;
sbit mccw_direction at TRISB.b7;

//variables
char rcdata;

//constants
const char motorcw=0x01;
const char motorccw=0x02;
const char motoridle=0x03;

// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End LCD module connections

int tp = 0;
int nothing;
char txt [4];
void _init()
{
TRISB.b1 =1;
TRISB.b2 =0;
TRISB.b4 =1;
TRISB.b5 =1;
// intilisation SPI
SPI1_Init_Advanced(_SPI_SLAVE_SS_ENABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_LOW_2_HIGH);
// Initialisation LCD
LCD_Init();
LCD_Cmd(_LCD_CLEAR);
LCD_Cmd(_LCD_CURSOR_OFF);
}
void main(){
_init();
LCD_out(1,1,"température");
while(1)
{
tp=SPI1_Read(nothing);
IntToStr(tp,txt);
LCD_out(2,1,txt);
}
}
A voir également: