打印

STR911 SPI做主收不到数据

[复制链接]
2830|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
john78|  楼主 | 2007-11-5 21:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
ST, spi, IO, gp, GPIO
  GPIO_StructInit(&GPIO_InitStruct);      
  GPIO_InitStruct.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStruct.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStruct.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStruct.GPIO_Alternate = GPIO_InputAlt1  ;
  GPIO_Init(GPIO5,&GPIO_InitStruct);
  
  
  GPIO_StructInit(&GPIO_InitStruct);      
  GPIO_InitStruct.GPIO_Pin        =  GPIO_Pin_4|GPIO_Pin_5;//|GPIO_Pin_7;         
  GPIO_InitStruct.GPIO_Direction  =  GPIO_PinOutput;
  GPIO_InitStruct.GPIO_Alternate  =  GPIO_OutputAlt2;
  GPIO_InitStruct.GPIO_Type       =  GPIO_Type_PushPull ;
  GPIO_InitStruct.GPIO_IPConnected=  GPIO_IPConnected_Disable;
  GPIO_Init(GPIO5,&GPIO_InitStruct);
  GPIO_StructInit(&GPIO_InitStruct);        
  GPIO_InitStruct.GPIO_Pin =  GPIO_Pin_7;         //这个引脚自己控制
  GPIO_InitStruct.GPIO_Direction =  GPIO_PinOutput;
  GPIO_InitStruct.GPIO_Alternate = GPIO_OutputAlt1;
  GPIO_Init(GPIO5,&GPIO_InitStruct);

  SSP_DeInit(SSP0);
  SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;
  SSP_InitStructure.SSP_Mode        = SSP_Mode_Master;
  SSP_InitStructure.SSP_CPOL        = SSP_CPOL_Low;
  SSP_InitStructure.SSP_CPHA        = SSP_CPHA_1Edge;
  SSP_InitStructure.SSP_DataSize    = SSP_DataSize_8b;
  SSP_InitStructure.SSP_ClockRate   = 10;
  SSP_InitStructure.SSP_ClockPrescaler = 96;

  SSP_Init(SSP0, &SSP_InitStructure);
  SSP_Cmd(SSP0, ENABLE);

发送接收

U8 enc28j60ReadOp(U8 op, U8 address)
{
  
  U8 da; 
  GPIO_WriteBit(GPIO5,GPIO_Pin_7,Bit_RESET)
  SSP_SendData(0x19);
  while(SSP_GetFlagStatus(SSP0, SSP_FLAG_Busy)==SET);  //接收数据
  SSP_SendData(SSP0,0X00);  //发送一个无效数据=接收
  while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty)==RESET);
  da = SSP_ReceiveData(SSP0);
  GPIO_WriteBit(GPIO5,GPIO_Pin_7,Bit_SET);
  return(da);
  
}

用逻辑分析仪观察,有数据回应,但发送接收返回的始终是0
不知道那里有错.
沙发
一览| | 2007-11-6 08:59 | 只看该作者

参考

u8 SSP_SendByte(SSP_TypeDef* SSPx,u8 byte)
{
  /* Send byte through the SSP0 peripheral */    
  SSPx->DR = byte;    

  /* Loop while Transmit FIFO is full */
  while(SSP_GetFlagStatus(SSPx, SSP_FLAG_TxFifoEmpty) == RESET);

  /* Loop while Receive FIFO is empty */
  while(SSP_GetFlagStatus(SSPx, SSP_FLAG_RxFifoNotEmpty) == RESET);    

  /* Return the byte read from the SSP bus */
  return(SSPx->DR);     
}

SSP_SendData(0x19); (发送命令后需要把缓冲区读空)

使用特权

评论回复
板凳
john78|  楼主 | 2007-11-6 23:08 | 只看该作者

还是不行

谢谢 一览

代码已经改成
static U8 SSP_SendByte(U8 byte)
{
  /* Send byte through the SSP0 peripheral */    
  SSP0->DR = byte;     // same as SSP_SendData 

  /* Loop while Transmit FIFO is full */
  while(SSP_GetFlagStatus(SSP0, SSP_FLAG_TxFifoEmpty) == RESET);

  /* Loop while Receive FIFO is empty */
  while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty) == RESET);    

  /* Return the byte read from the SSP bus */
  return(SSP0->DR); // same as SSP_ReceiveData     
}

U8 ReadOp(U8 op, U8 address)
{
da = SSP_SendByte(0x19);
da = SSP_SendByte(0xA5);
return da;
}
返回的值还是0X00
用逻辑分析仪观察返回的是0X58

不知道还有哪里没有设置好.

使用特权

评论回复
地板
john78|  楼主 | 2007-11-6 23:17 | 只看该作者

逻辑

使用特权

评论回复
5
STF| | 2007-11-7 10:13 | 只看该作者

STR9-Eval SSP 例子

你好,

ST 评估版上有一个 spi flash, 这个程序会先写数据然后读这个外部存储。你可以比较一下。

Regards,
Stephane 
相关链接:https://bbs.21ic.com/upfiles/img/200711/200711710835260.zip

使用特权

评论回复
6
一览| | 2007-11-7 11:51 | 只看该作者

参考

SSP_InitStructure.SSP_CPOL      = SSP_CPOL_Low;
SSP_InitStructure.SSP_CPHA     = SSP_CPHA_1Edge;


注意CPOL 与CPHA的配置要适合slave接口要求。

使用特权

评论回复
7
john78|  楼主 | 2007-11-7 12:59 | 只看该作者

CPHA=0,CPOL=0

器件要求:CPHA=0,CPOL=0
这个设置应该每错吧

SSP_InitStructure.SSP_CPOL      = SSP_CPOL_Low;
SSP_InitStructure.SSP_CPHA     = SSP_CPHA_1Edge; 

使用特权

评论回复
8
唐靖丰| | 2007-11-10 21:31 | 只看该作者

还是看看,你的配置

我也遇到过类似的问题,我曾经用一个SPI端口联了多个设备,但每个设备的配置就不太相同,所以,经常需要切换配置后才能顺利的读写设备。当时也遇到过你说的问题,大都是配置或者重复配置出的问题,

另外,有一次,我忘了在CONFIG.H中将SSP选中,结果似乎也出过问题。
91X还不错,我用得很好。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

70

主题

220

帖子

1

粉丝