MC9S12C128 - Question about MISO pin in SPI communication

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC9S12C128 - Question about MISO pin in SPI communication

2,842 Views
M3H0
Contributor I
Hi,

I'm using a MC9S12C128 with ICC12 compiler and I'm trying to communicate it with a MAX7317 I/O expander.

 I have succeed to write the I/O expander in order to change the state of the pins configured as outputs and also to read the state of the inputs. I can see with the oscilloscope that the device tell me when the input has changed.

My problem is that the MISO pin of the Microcontroller has a voltage of 4.86V and then when the MAX7317 sends something, the microcontroller receives always 0xFF in the SPIDR because even when the MAX7317 sends a logical NULL, the voltage received in the microcontroller is 3,8V.

The voltage supply of the MAX7317 is 3.3V. Can it be the problem?

That is something normal (that MISO pin has 5V)? Am I doing something wrong? Should I do something different appart from enabling the SPI module (I think it is right configured as the microcontroller communicates with the MAX7317)?

I attach the datasheet of the MAX7317 and I post my code. Thank you in advance.

Best regards
Oroitz Elgezabal

#include <mc9s12c128.h>
#include <datatypes.h>
#include <ofunc.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>


//Definition of the variables
UINT8 data, answer, BCD, bla;

//Definition of the functions
void WGPIO_spi(int data){
    while(!(SPISR & 0b00100000)); // wait until write is permissible
    SPIDR  = data; // output the byte to the SPI $00DD
}

UINT8 RGPIO_spi(void){
    while(!(SPISR & 0b10000000));  // wait until communication is complete
    return(SPIDR); // clear the SPIF flag.
}

void GPIO_on(){
     PORTA &= ~0x01; //$0000
}

void GPIO_off(){
     PORTA |= 0x01;
}

void init_SPI(){
    SPICR1 = 0x50; // SPICR1=0b01010100/0x54 $00D8
    SPICR2 = 0x00; //$00D9
       DDRM = 0x38; //set SS,SCK,MOSI lines of the µC to Output $0252
    PTM=0x00;
       SPIBR=0x43; //Bus clock:8MHz --> prescaler:80 --> SCK:100 KHz $00DA
    GPIO_off();
}

void main (void){
     bla=10;
    //Configuration of the chip select pin
    DDRA  = 0x01; // Port A, Pin 0 controls Shutdown of MAX7317

    //Configuration & initialization of the SPI module
    init_SPI();

    ledon(1);
    delay_ms(1000);
    ledoff(1);
   
    GPIO_on(); //Enable MAX7317 - /CS driven LOW
    delay_us(5);
    WGPIO_spi(0x0A); //Address of "Write ports P[0:9] with same output level"
    RGPIO_spi(); //Dummy read
    WGPIO_spi(0x01); //P[0:9] set as inputs
    delay_us(50);
    GPIO_off(); //Disable MAX7317 - /CS driven HIGH
   
    delay_ms(500);
   
    while(1) {
        GPIO_on(); // Drive /CS LOW
        delay_us(1);
        WGPIO_spi(0x8E); //Address of "Read input ports P[9:8]"
        RGPIO_spi(); //Dummy read
        WGPIO_spi(0x01); //Dummy byte sent (it will be ignored)
        delay_us(50);
        GPIO_off(); // Drive /CS HIGH
        ledon(1);
       
        delay_us(100);
       
        //Establish a new communication in order to get the desired data
        GPIO_on();
        delay_us(1);
        WGPIO_spi(0x03); //Address of P5
        RGPIO_spi(); //Dummy read
        WGPIO_spi(0x00); //P5 set as output
        data=RGPIO_spi(); //Get the value of the inputs
        delay_us(50);
        GPIO_off();
        ledoff(1);
        delay_ms(500);
    }
}

--
Alban Edit: FSL Part Number must figure in Message Subject line.



Message Edited by Alban on 2007-07-17 12:08 PM

 

MAX7317.pdf

Message Edited by t.dowe on 2009-10-21 12:16 AM
Labels (1)
0 Kudos
Reply
2 Replies

720 Views
Alban
Senior Contributor II
Hello,

Yes, the two I/O must use a compatible level.
You can read
AN2433 - 5V to 3V Design Considerations | Documentation | pdf
The move from 5V to 3V technology creates a challenging scenario for system designers. This application note will address the benefits that such a change brings and the design considerations that make the transition as smooth as possible.

It explains how to mix/translate levels.
Cheers,
Alban.
0 Kudos
Reply

720 Views
M3H0
Contributor I
Thank you Alban that was exactly the problem. Now it works
0 Kudos
Reply