STM32F105 I2S Master Clock ausgeben auf PC6 geht nicht

OP #1995308
Lesenswert?

Hallo zusammen...

Ich versuche bei einem STM32F105RB auf dem I2S2 einen Master Clock 
ausgeben zu lassen...

Die Leitungen SD, WS und CK funktionieren einwandfrei... Nur am PC6 
kommt nichts raus...

Quarz ist 6MHz

Da hätte ich noch eine Frage, wenn ich für I2S zb 8KHz Sampling 
konfiguriere,
Von welcher arbeits Frequenz geht dann der Controller aus?


Danke schonmal


Hier mein code:
1
/**
2
*****************************************************************************
3
**
4
**  File        : main.c
5
**
6
**  Abstract    : main function.
7
**
8
**  Functions   : main
9
**
10
**  Environment : Atollic TrueSTUDIO/STM32
11
**                STMicroelectronics STM32F10x Standard Peripherals Library
12
**
13
**  Distribution: The file is distributed “as is,” without any warranty
14
**                of any kind.
15
**
16
**  (c)Copyright Atollic AB.
17
**
18
**
19
*****************************************************************************
20
*/
21

22
/* Includes */
23
#include "stm32f10x.h"
24

25
GPIO_InitTypeDef GPIO_InitStructure;
26
I2S_InitTypeDef I2S_InitStructure;
27
ErrorStatus HSEStartUpStatus;
28

29
unsigned int I2S2_Buffer_Tx[] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C,
30
                                  0x0D0E, 0x0F10, 0x1112, 0x1314, 0x1516, 0x1718,
31
                                  0x191A, 0x1B1C, 0x1D1E, 0x1F20, 0x2122, 0x2324,
32
                                  0x2526, 0x2728, 0x292A, 0x2B2C, 0x2D2E, 0x2F30,
33
                                  0x3132, 0x3334, 0x3536, 0x3738, 0x393A, 0x3B3C,
34
                                  0x3D3E, 0x3F40};
35

36
void RCC_Configuration(void);
37
void GPIO_Configuration(void);
38

39
void setup(void)
40
{
41
/*
42
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
43
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
44
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
45
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
46
  GPIO_Init(GPIOB, &GPIO_InitStructure);  //Adresse des Struktes übergeben damit dieses Ausgelesen werden kann!
47
*/
48
  /* I2S peripheral configuration */
49
  I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
50
  I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
51
  I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
52
  I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;
53
  I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
54

55
  /* I2S2 Master Transmitter to I2S2 Slave Receiver communication ------------*/
56
  /* I2S2 configuration */
57
  I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
58
  I2S_Init(SPI2, &I2S_InitStructure);
59

60
  /* Enable the I2S2 */
61
    I2S_Cmd(SPI2, ENABLE);
62
}
63

64
void delay_clk(unsigned int clocks)
65
{
66
  while(clocks) clocks--;
67
}
68

69
int main(void)
70
{
71
  RCC_Configuration();
72
  GPIO_Configuration();
73
    setup();
74
    //Warten bis der Sende Buffer leer ist!
75
  int i = 0;
76

77
  while (1)
78
  {
79
  i++;
80
  while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
81
  SPI_I2S_SendData(SPI2, I2S2_Buffer_Tx[i++]);
82

83
  if( i == sizeof(I2S2_Buffer_Tx)) i = 0;
84
  }
85
}
86

87

88

89

90

91

92

93

94

95
void RCC_Configuration(void)
96
{
97
  /* RCC system reset(for debug purpose) */
98
  RCC_DeInit();
99

100
  /* Enable HSE */
101
  RCC_HSEConfig(RCC_HSE_ON);
102

103
  /* Wait till HSE is ready */
104
  HSEStartUpStatus = RCC_WaitForHSEStartUp();
105

106
  if(HSEStartUpStatus == SUCCESS)
107
  {
108
    /* Enable Prefetch Buffer */
109
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
110

111
    /* Flash 2 wait state */
112
    FLASH_SetLatency(FLASH_Latency_2);
113

114
    /* HCLK = SYSCLK */
115
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
116

117
    /* PCLK2 = HCLK */
118
    RCC_PCLK2Config(RCC_HCLK_Div1);
119

120
    /* PCLK1 = HCLK/2 */
121
    RCC_PCLK1Config(RCC_HCLK_Div2);
122

123
    /* ADCCLK = PCLK2/4 */
124
    RCC_ADCCLKConfig(RCC_PCLK2_Div4);
125

126

127
    /* Configure PLLs *********************************************************/
128
    /* PLL2 configuration: PLL2CLK = (HSE (6MHz) / 3) * 20 = 40 MHz */
129
    RCC_PREDIV2Config(RCC_PREDIV2_Div3);
130
    RCC_PLL2Config(RCC_PLL2Mul_20);
131

132
    /* Enable PLL2 */
133
    RCC_PLL2Cmd(ENABLE);
134

135
    /* Wait till PLL2 is ready */
136
    while (RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET)
137
    {}
138

139
    /* PLL configuration: PLLCLK = (PLL2 / 5) * 9 = 72 MHz */
140
    RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2, RCC_PREDIV1_Div5);
141
    RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_9);
142

143
    /* PPL3 configuration: PLL3CLK = (HSE / 5) * 11 = PLL3_VCO = 110 MHz */
144
    RCC_PLL3Config(RCC_PLL3Mul_20);
145
    /* Enable PLL3 */
146
    RCC_PLL3Cmd(ENABLE);
147
    /* Wait till PLL3 is ready */
148
    while (RCC_GetFlagStatus(RCC_FLAG_PLL3RDY) == RESET)
149
    {}
150

151
    /* Configure I2S clock source: On Connectivity-Line Devices, the I2S can be
152
        clocked by PLL3 VCO instead of SYS_CLK in order to guarantee higher
153
        precision */
154
    RCC_I2S2CLKConfig(RCC_I2S2CLKSource_PLL3_VCO);
155

156
    /* Enable PLL */
157
    RCC_PLLCmd(ENABLE);
158
    /* Wait till PLL is ready */
159
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
160

161
    /* Select PLL as system clock source */
162
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
163

164
    /* Wait till PLL is used as system clock source */
165
    while(RCC_GetSYSCLKSource() != 0x08);
166
  }
167

168
  /* Enable peripheral clocks --------------------------------------------------*/
169
  /* GPIOA, GPIOB and AFIO clocks enable */
170
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
171

172

173
  /* SPI2 and SPI3 clocks enable */
174
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
175
}
176

177

178
void GPIO_Configuration(void)
179
{
180
  GPIO_InitTypeDef GPIO_InitStructure;
181

182
  /* Configure SPI2 pins: CK, WS and SD---------------------------------*/
183
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_15 ;
184
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
185
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
186
  GPIO_Init(GPIOB, &GPIO_InitStructure);
187

188
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
189
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
190
  GPIO_Init(GPIOC, &GPIO_InitStructure);
191
}
192

193

194
/*
195
 * Minimal __assert_func used by the assert() macro
196
 * */
197
void __assert_func(const char *file, int line, const char *func, const char *failedexpr)
198
{
199
  while(1)
200
  {}
201
}
202

203
/*
204
 * Minimal __assert() uses __assert__func()
205
 * */
206
void __assert(const char *file, int line, const char *failedexpr)
207
{
208
   __assert_func (file, line, 0x00, failedexpr);
209
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren