当前位置: 代码迷 >> 单片机 >> C8051F330 SPI从机程序没法正常运行
  详细解决方案

C8051F330 SPI从机程序没法正常运行

热度:84   发布时间:2016-04-28 15:43:25.0
C8051F330 SPI从机程序无法正常运行
以下是我用C8051F330SPI模块做的从机程序。采用的是空闲时高电平,上升沿采样的模式。但是当我和相应主机通信时,在MISO上却始终是高电平,从机不能正常发送数据。困扰好久,求大侠给点指点,万分感激

以下是代码
//-----------------------------------------
// F33x_SPI0_Slave.c
//-----------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program configures a C8051F33x as a SPI Slave. The 'F33x MCU
// is configured in 4-wire Slave Mode.
//
// This example is intended to be used with the SPI0_Master example.
//
// Pinout:
//
// P0.0 - SPI SCK    (digital input, open-drain)
// P0.1 - SPI MISO   (digital output, push-pull)
// P0.2 - SPI MOSI   (digital input, open-drain)
// P0.3 - SPI NSS    (digital input, open-drain)
//
// P1.3 - LED        (digital output, push-pull)
//
// all other port pins unused.
//
//
// How To Test:
//
// 1) Download the code to a F330-TB that is connected as above to
//    another device running the SPI0_Master code.
// 2) Verify that the J6 jumper is not populated.
// 3) Verify the LED pins of jumper J3 are populated.
// 4) Run the code.
// 5) If the communication passes, the LEDs on both the Master and Slave
//    boards will blink slowly. If it fails, the LEDs will be OFF.
//
// Target:         C8051F33x
// Tool chain:     Keil C51 7.50 / Keil EVAL C51
// Command Line:   None
//
// Release 1.0
//    -Initial Revision (TP)
//    -12 DEC 2006
//

//-----------------------------------------
// Includes
//-----------------------------------------

#include <C8051F330.h>                 // SFR declarations

//-----------------------------------------
// Global Constants
//-----------------------------------------

#define SYSCLK             24500000    // Internal oscillator frequency in Hz

#define MAX_BUFFER_SIZE    8           // Maximum buffer Master will send

// Instruction Set
#define  SLAVE_LED_ON      0x01        // Turn the Slave LED on
#define  SLAVE_LED_OFF     0x02        // Turn the Slave LED off