SPI 0 port not working with new 9S12DG256CPV, but does work using 9S12DG256BCPV part

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

SPI 0 port not working with new 9S12DG256CPV, but does work using 9S12DG256BCPV part

3,731 Views
darrin
Contributor II
I have been using the 9S12DG256BCPV part for some time now and have had no trouble.
We just received a shipment of 9S12DG256CPV parts since the "B" part has become obsolete.
 
This new 9S12DG256CPV (0L01Y mask) part will not work (i have tried 5 parts so far), and I traced it to the SPI0 port. I use SPI0 as a Master with SS turned off (I control the chip select myself). The clock never operates when I send a byte.  The same exact code works perfectly in a 9S12DG256BCPV (1K79X).
 
Please help
 
 
 
Labels (1)
0 Kudos
16 Replies

1,153 Views
sturan_16bit
Contributor I
Dear Darrin;
 
i have been tring to communicate SPI I/O expander by using the same microcontroller. MC9S12DG256CPVE and also MC9S12DG256CFUE. But it is impossible to implement it by using SPI0
module. Plus i m using SS pin to select slave device. But there is no low level on this pin during SPI transmission in addtion to not having serial clock on SCK pin.
 
could anyone say me that there is no way to communicate with SPI0 module within MC9S12DG256CXXE.
 
best regards.
0 Kudos

1,153 Views
bigmac
Specialist III
Hello Serkan,
 
I think you will also need to control the /SS pin as a GP output.  This is because your I/O expander device (MCP23S17) requires that /SS remain low for more than one send byte.  It would help if you post your SPI initialisation code and communications code, to ascertain why the SPI does not seem to work.
 
Regards,
Mac
 
0 Kudos

1,153 Views
sturan_16bit
Contributor I
Now i m using SPI1 module within the MC9S12DG256CFUE microcontroller. Now there is no problem to see serial clock, cs goes low, and master information which are being sent.
 
Now, the problem is not to take MCP23S17 information. Because it can not drive MISO pin. İ m seing the pin level during transmission. But it can not be high level or if i use pull-up device it can not be low level. therefore i can only take 0x00 and 0xFF values from the slave.
 
could you say me what kind of connection i have to do respect to MCP23S17 SO output level.
 
best regards.
0 Kudos

1,153 Views
bigmac
Specialist III
Hello Serkan,
 
If my interpretation of the data sheet is correct, there are a number of factors within your code that would be incompatible with the MCP23S17 device, and prevent communications. There is also other code that is unnecessary.
  1. I note that you have set both the control bits SSOE and MODFEN. This will cause the /SS pin to be an output that is directly controlled by the SPI module - the pin will automatically become active (low) prior to sending each byte data, and will de-activate on completion of the byte.  However, this does not appear compatible with the requirements of the port expander device, where /SS must remain active while at least three bytes are sent, and possibly more bytes. Thus, the pin used for /SS output will need to be directly controlled by your code, and both the control bits should be cleared. This is the issue I was alluding to in my previous post.  This would also explain why you are observing that the MISO line remains high-Z output.
  2. You have set up the SPI for CPOL = 0 and CPHA = 1. The data sheet for the MCP23S17 specifies that it is compatible with either of the SPI modes 0,0 or 1,1.
  3. You have configured the DDR bits associated with the SPI signals. This is unnecessary because the SPI module will over-ride the DDR settings when it is enabled. However, you will still need to set the /SS pin as an output because it is now under port control.
  4. You have defined the global array variable SpiDummy as a long.  Since the SPI handles only a single byte at a time, it would be more appropriate for the variable to be defined as byte or unsigned char.
  5. I am unsure of what your test code is trying to achieve, but it would seem that the second byte sent, following the command byte, is incorrect. The first command byte appears correct as a read command. Assuming power-up default settings within the slave, the second byte should be a register address value within the range 0x00 to 0x15. You would then need to send "dummy" values in order to receive the data from the specified address, and possibly subsequent addresses. You also appear not to have taken into account that the first two values returned, in response to the command byte and the address value, will be "garbage".
I have adapted and altered your code to demonstrate what I mean. The main() function is intended to read all 22 byte registers within the MCP23S17, and store their values within the SpiDummy array.
 
Regards,
Mac

/* Global variable */
byte SpiDummy[22];
 
/* Command bytes */
#define READ0  0x41
#define WRITE0 0x40
 
#define SS  PTM_PTM3
 
void Spi0Init(void) // MASTER SPI
{
  MODRR = 0x14;    // ??
  DDRM_DDRM3 = 1;  // SS pin configured as output
  SPI0BR = 0x01;   // fclk = fbus/4 (4Mhz, for fbus = 16 MHz)
  SPI0CR2 = 0x00;
  SPI0CR1 = 0x50;  // CPOL = 0, CPHA = 0
}
 
byte SPI_trans(byte value)     /* SPI transaction, single byte */
{
  while (SPI0SR_SPTEF != 1);  /* wait until ready to send */
  SPI0DR = value;             /* send byte */
  while(SPI0SR_SPIF != 1);    /* wait until transfer completed */
  return (SPI0DR);
}
 
void main(void)
{
  byte i;
 
  EnableInterrupts;
  Spi0Init();
 
  /* Read all registers */
  SS = 0;                       /* Enable /SS (/CS) */
  SPI_trans(READ0);             /* Send command byte */
  SPI_trans(0);                 /* Start at register address 0 */
  for (i = 0; i < 22; i++)
     SpiDummy[i] = SPI_trans(0);/* Send dummy value & store return value */
  SS = 1;                       /* Disable /SS */
 
  for ( ; ; ) { }               /* wait forever */
}
0 Kudos

1,153 Views
sturan_16bit
Contributor I
Dear Mac
 
i have used your codes, and i can see SCK and MOSI values rigth.
 
But the problem is Slave OUT. if you examine MCP23S17 datasheet IODIRA and IODIRB registers are all FF as input after reset. So i have to read this register value as FF.
 
then when your code runs first 3th and 4the value must be 0xFF. But i m reading all value as 00. i observe the slave out pin. it can not drive MISO line. İt can only drive the line upto 1 Volt. İf i connect MISO with pull-up then i m reading only FF values. This mean i think the SO pin of MCP23S17 is all the time high-Z position.
 
Could you give any recommendation?
 
and also i m configuring MCP23S17 as following situation
 
SS = 0;                                                 // enable I/O expander
 SpiDummy[0]=WriteSPI(0x40);         // Opcode write mode, address 0x00
 SpiDummy[1]=WriteSPI(IODIRA);     // register adress 
 SpiDummy[2]=WriteSPI(0x00);        // data for port A as inputs 
SS = 1;                                               // disable I/O
 
SS = 0;                                                 // enable I/O expander
 SpiDummy[9]=WriteSPI(0x40);          // Opcode write mode, address 0x00
 SpiDummy[10]=WriteSPI(GPIOA);    // register adress
 SpiDummy[11]=WriteSPI(0xFF);       // output data       
SS = 1;                                               // disable I/O
 
now i should see logic one on all of GPIOA pins. but i can not see altough i can see the SPI writes rigth value on ascilloscope
 
best regards.
0 Kudos

1,153 Views
Rajendrask
Contributor I
Hi,
 
I am also not able to read form MISO line. My CS,CLK,MOSI lines are perfect. I am not able to see MISO. it's always low.
 
I am using STR910 Evaluation board woth MCP23s17 @ 2Mbit/second.
 
below is my code.,
 
Please correct me if i am wrong. Can i have any help for this.
 
Thanks & Regards,
Rajendra
 
 
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name          : main.c
* Author             : MCD Application Team
* Date First Issued  : 05/18/2006 : Version 1.0
* Description        : Main program body
********************************************************************************
* History:
* 05/22/2007 : Version 1.2
* 05/24/2006 : Version 1.1
* 05/18/2006 : Version 1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "91x_lib.h"
#include <stdio.h>
#include "spi_flash.h"
#define IODIRA    0x00
#define IODIRB    0x01
#define IPOLA     0x02
#define IPOLB     0x03
#define GPINTENA  0x04
#define GPINTENB  0x05
#define DEFVALA   0x06
#define DEFVALB   0x07
#define INTCONA   0x08
#define INTCONB   0x09
#define IOCONA    0x0A
#define IOCONB    0x0B
#define GPPUA     0x0C
#define GPPUB     0x0D
#define INTFA     0x0E
#define INTFB     0x0F
#define INTCAPA   0x010
#define INTCAPB   0x011
#define GPIOA     0x012
#define GPIOB     0x013
#define OLATA     0x014
#define OLATB     0x015
unsigned int  LEDPattern = 0x000;  //This is the pattern which gets manipulated via algorithms

void GPIO_Configuration(void);
void SCU_Configuration(void);
void delay1(void);
void InitMCP( void );
void Write23X17(unsigned char reg, unsigned char data);
unsigned char Read23X17(unsigned char reg);
void   Temp_calculation(void);
SSP_InitTypeDef   SSP_InitStructure;
/*******************************************************************************
* Function Name  : main
* Description    : Main program
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main()
{
  u8 n=0;

  SCU_MCLKSourceConfig(SCU_MCLK_OSC);    /*Use OSC as the default clock source*/
  SCU_PCLKDivisorConfig(SCU_PCLK_Div1);
 
  /* SCU configuration */
  SCU_Configuration();
  /* GPIO pins configuration */
  GPIO_Configuration();
  /* SSP0 configuration */
  SSP_DeInit(SSP1);
 
  SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;
  SSP_InitStructure.SSP_Mode = SSP_Mode_Master;
  SSP_InitStructure.SSP_CPOL = SSP_CPOL_High;
  SSP_InitStructure.SSP_CPHA = SSP_CPHA_2Edge;
  SSP_InitStructure.SSP_DataSize = SSP_DataSize_16b;
  SSP_InitStructure.SSP_ClockRate = 1;
  SSP_InitStructure.SSP_ClockPrescaler = 4; 
  SSP_Init(SSP1, &SSP_InitStructure);
  SSP_Cmd(SSP1, ENABLE);
  SSP_FLASH_CS_HIGH();
  delay1();
 
  SSP_FLASH_CS_LOW();
  delay1();
 
/***********I/O Expander code...*********/ 
 
  InitMCP();
/***********I/O Expander code...*********/ 
 
 
/***********I/O Expander code...*********/ 
    Write23X17(GPINTENA, 0x00); // Disable Int-on-Change
    Write23X17(GPINTENB, 0x00); // Disable Int-on-Change
   
    n = Read23X17(GPIOA);    // Read GPIO to clear INT 'Just in Case'
    n = Read23X17(GPIOB);    // Read GPIO to clear INT 'Just in Case'
   
    Write23X17(GPIOA, LEDPattern << 4);//
    n = Read23X17(GPIOA);    // Read GPIO to clear INT 'Just in Case'   
    Write23X17(GPIOB, (LEDPattern & 0xFF0) >> 4); //   
    n = Read23X17(GPIOB);    // Read GPIO to clear INT 'Just in Case'
   
/***********I/O Expander code...*********/   
/*********Temperature code...**********/
   Temp_calculation();
/*********Temperature code...**********/  
  while(1);
}
/*************************************************************
   Function Name:  InitMCP                                        
   Return Value:   void                                          
   Parameters:     void                    
   Description:    Initializes the MCP23X17 devices      
**************************************************************/
void InitMCP( void )
{
//Set Mode to SPI
//  SetSSP(SPIMODE);
//Configure 23S17
  SSP_FLASH_CS_LOW();
 
  Write23X17(GPPUA,  0xFF);   // Pullups
  Write23X17(GPPUB,  0xFF);   // Pullups
 
  Write23X17(IOCONA, 0x70);   // Change this to 0x30 if not working Rajendra....
  Write23X17(IOCONB, 0x70);   // Change this to 0x30 if not working Rajendra....
 
  Write23X17(IODIRA, 0xFF);   //All inputs by default (this is the POR default)
  Write23X17(IODIRB, 0xFF);   //All inputs by default (this is the POR default)
 
  SSP_FLASH_CS_HIGH();
 
}
/*************************************************************
   Function Name:  Write23X17                                        
   Return Value:   void                                          
   Parameters:     Register address, Data                   
   Description:    Writes a 23X17 register. I2C or SPI is in
                   global byte    
**************************************************************/
void Write23X17(unsigned char reg, unsigned char data)
{
  SSP_FLASH_CS_LOW(); 
 
  SSP_SendData(SSP1,0x40); 
  SSP_SendData(SSP1,reg);   
  SSP_SendData(SSP1,data);     
 
  SSP_FLASH_CS_HIGH(); 
}
/*************************************************************
   Function Name:  Read23X17                                        
   Return Value:   void                                          
   Parameters:     Register address                   
   Description:    Reads a 23X17 register. I2C or SPI is in
                   global byte    
**************************************************************/
unsigned char Read23X17(unsigned char reg)
{
  unsigned char num;
  SSP_FLASH_CS_LOW(); 
 
  SSP_SendData(SSP1,0x41); 
  SSP_SendData(SSP1,reg); 
 
  SSP_SendData(SSP1,0xA5);    //Send dummy data for as per SPI Concept.:----rajendra... 
  num = SSP_ReceiveData(SSP1);    
 
  SSP_FLASH_CS_HIGH(); 
  return(num);
}
/*******************************************************************************
* Function Name  : GPIO_Configuration
* Description    : Configure the used I/O ports pins
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;
 
  GPIO_DeInit(GPIO3);
   /*Gonfigure SSP1_nSS pins */
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
  GPIO_Init (GPIO3, &GPIO_InitStructure);
   /*Gonfigure SSP1_CLK, SSP1_MOSI*/
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2  ;
  GPIO_Init (GPIO3, &GPIO_InitStructure);
  /*Gonfigure SSP1_MISO pin */
  GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1  ;
  GPIO_Init (GPIO3, &GPIO_InitStructure); 
}
/*******************************************************************************
* Function Name  : SCU_Configuration
* Description    : Configure the different system clocks
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void SCU_Configuration(void)
{
#ifdef SPI0   
  /* Enable the __SSP0 Clock */
  SCU_APBPeriphClockConfig(__SSP0 ,ENABLE);
  /* Enable the __GPIO5 for SSP0 Clock */
  SCU_APBPeriphClockConfig(__GPIO5 ,ENABLE);
#endif
 
#ifdef SPI1     
  /* Enable the __SSP1 Clock */
  SCU_APBPeriphClockConfig(__SSP1 ,ENABLE);
  /* Enable the __GPIO3 for SSP1 Clock */
  SCU_APBPeriphClockConfig(__GPIO3 ,ENABLE);
#endif
}
void delay1(void)
{
  int i,j;
  for (i=0;i<10;i++)
  {
      for (j=0;j<10;j++)
      ;
      
  }
}
void   Temp_calculation(void)
{
  u16  Temp = 0;
     SSP_SendData(SSP1,0xA5A5); 
     SSP_SendData(SSP1,0xA5A5);
     delay1();
     delay1();
     Temp= (SSP_ReceiveData(SSP1));
     Temp|= (SSP_ReceiveData(SSP1));
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
0 Kudos

1,153 Views
JamesTPDI
Contributor II
A possability
//You always have to read the status bit before transmitting (even if you know its state!) or the hardware hangs.
while(SPTEF_0 == 0);    //wait for ready to transmit
 SPI0DR   =  0xaa;    //do an 8 bit transfer
 
James
0 Kudos

1,153 Views
Rajendrask
Contributor I
Hi James,
 
Thnaks for your reply.
 
This is my detail observation.
 
My CLK are generating properly on trasnmission of data on MOSI line. CS also working proper.
 
Problem is that i am not able to read any regsiter value. it means MISO line is not working fine.
 
 
I am using STR910 evalutionn board and SPI1. From same SPI my temperature sensor and NVM are working fine. Only I/O Expander are not working.
 
 
I am having suspect on I/O Expander configuration. Please can you check configuration of MCP.
 
 
It will be great help if you look into this matter.
 
Rajendra
 
 
0 Kudos

1,153 Views
JamesTPDI
Contributor II
Sounds like your micro is working. I am running my own hardware and software design, so I can't offer any insight into the evaluation board H/W S/W. Sorry.
 
James
0 Kudos

1,153 Views
Rajendrask
Contributor I
Hi,
 
I am using STR910. This processor works on 3.5 volts.  MX2317 works on 4.5 to 5.5 volts range.
 
I am thinking this might be issue.>?  What you think for this?
 
 
 
Rajendra
0 Kudos

1,153 Views
bigmac
Specialist III
Hello Serkan,
 
Firstly, it is a good idea to install a pull-up resistor at the MISO line, to ensure a proper logic state when output from MCP23S17 is high-Z.
 
Using the oscilloscope, can you confirm that the /CS pin at the MCP23S17 is actually changing state, and correctly framing all bytes sent at MOSI?
 
For read mode, the slave output will be high-Z while the first two bytes are sent, and should output data, commencing with the third byte.  For write mode,  the slave output will remain high-Z for the whole process.  Writing the return value to SpiDummy[] will serve no useful purpose.
 
Regards,
Mac
 
0 Kudos

1,153 Views
sturan_16bit
Contributor I
Dear bigmac;
 
i think the problem is not only SS pin but also SPI module. Because SPI module must give serial clock altough it does not make SS pin low. But during to transmission i can not see any clock on real-time osciloscope.
 
And could you explain your advice about using DP IO. At MCP23S17 datasheet i have sent it by attachment page 32 has SPI timing figure 2-5. Only 50 ns CS setup time. it corresponds almost one CPU clock of MCU whose CPU clock is 48 Mhz.
 
And also i m sending you  my small part of project which has been written to solve this SPI fault.
 
Could you give any advice or could you change my code with respect to MCP23S17.
 
by the way i m going to try different SPI module within the same micro.
 
best regards. 

Message Edited by 16-bit on 2006-10-1102:57 AM

 

SPI_DG.zip

MCP23X17.pdf

Message Edited by t.dowe on 2009-10-20 11:13 PM
0 Kudos

1,153 Views
darrin
Contributor II
I use the SPI for communication between 2 DG256 chips configured as a Master / Slave setup.
In the Master chip, I use the SS pin, but I keep it as a normal I/O pin and turn the SS pin on/off myself (in my own code).
0 Kudos

1,153 Views
JamesTPDI
Contributor II
Did you get this resolved? I have just run into a similar problem. My SPI 0 runs after downloading code but not after reset. All works fine on the "B" version of the part.
0 Kudos

1,153 Views
darrin
Contributor II
Yes I figured it out,
 
I had to make sure I checked the SPI status register before I used the SPI to transmit.
 
The "B" version is not as forgiving as the plain version.
0 Kudos

1,153 Views
Alban
Senior Contributor II
Hi Darrin and Thanks for the feedback,

The B version is earlier than the non-B one.
Mainly because of Flash quality I would advise any new design to be done using the non-B version.
Actually, I imagine a E version should be available for RoHS and Pb Free compliance purposes. (Lead-free and RoHS Data)

With the mask set number: 9X99X you can get the list of Errata existing from a refining from the following search link: Errata.

Cheers,
Alban.
http://www.freescale.com/webapp/search/MainSERP.jsp?RELEVANCE=true&showAllCategories=false&SelectedA...
0 Kudos