STM32 SPI clock sinyalini göremiyorum.

Başlatan quigon1977, 15 Kasım 2015, 02:24:14

quigon1977

Merhaba, STM32L052 için alttaki programı yazdım ama spi clock sinyali çıkmıyor. Nerde hata yaptığımı gören varsa yardım lütfen.
Pini high-low yaptığım zaman çalışıyor ama spi modunda hareket yok.

#include "stm32l0xx.h"

unsigned char xr=123;

void sys_init()
{
RCC->ICSCR=0xC000;                // internal osilatör 4mhz yükseltildi
RCC->IOPENR  = 0xF;                 // a,b ve c portlari çalistirildi.

GPIOA->MODER = 0x5555A955;     // A portu  (a5 a6 a7 SPI) diğer pinler çıkış
GPIOB->MODER = 0x55555555;     // B portu komple çikis
GPIOC->MODER = 0x55555555;     // C portu komple çikis

RCC->APB2ENR = 0x1000;       // ADC clock enable , SPI(1) clock enable
SPI1->CR1 = 0x247;                // spi acik
   
}

void delay_ms(unsigned int nCount)
{
nCount*=520;
for(; nCount != 0; nCount--);
}



int main()
{
   
sys_init();

   
while(1)
{   

SPI1->DR = xr;
delay_ms(10);

   
}}

z

RCC->APB2ENR = 0x1000;       // ADC clock enable , SPI(1) clock enable

0x1000 de sadece 1 bit 1.

Bir bit nasıl hem ADC enb hem de SPI enb yapabilir?
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

quigon1977

Oradaki açıklama yanlış olmuş. Sadece SPI enable edildi.

Bit 12 SPI1EN: SPI1 clock enable bit
This bit is set and cleared by software.
0: SPI1 clock disabled
1: SPI1 clock enabled
Bits 11:10 Reserved, must be kept at reset

quigon1977

Debug yaparak hatayı buldum sanırım. Ama nasıl düzelir bilmiyorum. SPI haberleşmesi başlamadan önce MODF diye bir hata çıkıyor.
Açıklamasını işlemcinin datasheet inde buldum, alta ekliyorum. Bunu nasıl düzelteceğimi analayan varsa yardım lütfen.

Mode fault (MODF)
Mode fault occurs when the master device has its internal NSS signal (NSS pin in NSS
hardware mode, or SSI bit in NSS software mode) pulled low. This automatically sets the
MODF bit. Master mode fault affects the SPI interface in the following ways:
• The MODF bit is set and an SPI interrupt is generated if the ERRIE bit is set.
• The SPE bit is cleared. This blocks all output from the device and disables the SPI
interface.
• The MSTR bit is cleared, thus forcing the device into slave mode.
Use the following software sequence to clear the MODF bit:
1. Make a read or write access to the SPIx_SR register while the MODF bit is set.
2. Then write to the SPIx_CR1 register.
To avoid any multiple slave conflicts in a system comprising several MCUs, the NSS pin
must be pulled high during the MODF bit clearing sequence. The SPE and MSTR bits can
be restored to their original state after this clearing sequence. As a security, hardware does
not allow the SPE and MSTR bits to be set while the MODF bit is set. In a slave device the
MODF bit cannot be set except as the result of a previous multimaster conflict.