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****/