テスト用のあれこれ共用フォルダ
修訂 | b2ca88237ebbc6397c309a0f587b16c93b45f3ce (tree) |
---|---|
時間 | 2018-06-23 16:04:07 |
作者 | takemasa <suikan@user...> |
Commiter | takemasa |
SPI master has been debugged. I2C is under debugging.
So far, transmission is OK. Need to check the EEProm behavior on the
secodn transmission.
@@ -83,6 +83,7 @@ struct Platform | ||
83 | 83 | AbstractLogger * logger; ///< logging class object for debugger |
84 | 84 | AbstractSpiMaster * spi; ///< SPIport controler |
85 | 85 | AbstractSpiSlaveSpecifier * m95010; ///< 1kbit EEPROM |
86 | + AbstractI2CMaster * i2c1; ///< I2C controler | |
86 | 87 | |
87 | 88 | AbstractBitOut * led; |
88 | 89 | }; |
@@ -251,7 +251,7 @@ static void MX_SPI1_Init(void) | ||
251 | 251 | hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; |
252 | 252 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
253 | 253 | hspi1.Init.NSS = SPI_NSS_SOFT; |
254 | - hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; | |
254 | + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256; | |
255 | 255 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
256 | 256 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
257 | 257 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
@@ -82,6 +82,8 @@ void InitPlatform() | ||
82 | 82 | SPI_CS_GPIO_Port, |
83 | 83 | SPI_CS_Pin); |
84 | 84 | |
85 | + murasaki::platform.i2c1 = new murasaki::I2cMaster(&hi2c1); | |
86 | + | |
85 | 87 | // Setting the debugger |
86 | 88 | murasaki::debugger = new murasaki::Debugger(murasaki::platform.logger); |
87 | 89 | // Set the debugger as AutoRePrint mode, for the easy operation. |
@@ -89,6 +91,8 @@ void InitPlatform() | ||
89 | 91 | |
90 | 92 | } |
91 | 93 | |
94 | +#define M24128_ADDR 0x50 | |
95 | + | |
92 | 96 | /** |
93 | 97 | * @brief The body of the real application. |
94 | 98 | * @ingroup MURASAKI_PLATFORM_GROUP |
@@ -106,23 +110,49 @@ void ExecPlatform() | ||
106 | 110 | // counter for the demonstration. |
107 | 111 | static int count = 0; |
108 | 112 | |
109 | - uint8_t txbuf[2]; | |
110 | - uint8_t rxbuf[2]; | |
113 | + uint8_t txbuf[10]; | |
114 | + uint8_t rxbuf[10]; | |
111 | 115 | |
112 | - txbuf[0] = 0x09; // RDSR instruction for m95010. | |
116 | + txbuf[0] = 0x05; // RDSR instruction for m95010. | |
113 | 117 | |
114 | 118 | // Loop forever |
115 | 119 | while (true) { |
116 | 120 | // Toggle LED. |
117 | 121 | murasaki::platform.led->Toggle(); |
118 | - | |
122 | +#if 0 | |
123 | + // SPI test | |
119 | 124 | murasaki::platform.spi->TransmitAndReceive(murasaki::platform.m95010, |
120 | 125 | txbuf, rxbuf, 2); |
121 | 126 | |
122 | 127 | // print a message with counter value to the console. |
123 | - murasaki::debugger->Printf("Hello %d status register = 0x%02x\n\r", | |
128 | + murasaki::debugger->Printf("Hello %d SPI status register = 0x%02x\n\r", | |
124 | 129 | count, rxbuf[1]); |
130 | +#else | |
131 | + //I2C test | |
132 | + // Writting 0xdeadbeaf from address 0 | |
133 | + txbuf[0] = 0; // memory address upper byte | |
134 | + txbuf[1] = 0; // memory address lower byte | |
135 | + txbuf[2] = 0xde; // data of address 0 | |
136 | + txbuf[3] = 0xad; // data of address 0 | |
137 | + txbuf[4] = 0xbe; // data of address 0 | |
138 | + txbuf[5] = 0xef; // data of address 0 | |
139 | + | |
140 | + // Write data | |
141 | + murasaki::platform.i2c1->Transmit(M24128_ADDR, txbuf, 6); | |
142 | + murasaki::debugger->Printf("Hello %d I2C Transmit \n\r", count); | |
143 | + | |
144 | + // Dummy write to set the address | |
145 | + murasaki::platform.i2c1->Transmit(M24128_ADDR, txbuf, 2); | |
146 | + murasaki::debugger->Printf("Hello %d I2C Transmit Dummy \n\r", count); | |
147 | + | |
148 | + // Read from the address | |
149 | + murasaki::platform.i2c1->Receive(M24128_ADDR, rxbuf, 4); | |
125 | 150 | |
151 | + | |
152 | + // print a message with counter value to the console. | |
153 | + murasaki::debugger->Printf("Hello %d I2C Received 0x%02x\n\r", count, | |
154 | + rxbuf[0]); | |
155 | +#endif | |
126 | 156 | // update the counter value. |
127 | 157 | count++; |
128 | 158 |
@@ -277,6 +307,8 @@ void HAL_SPI_ErrorCallback(SPI_HandleTypeDef * hspi) { | ||
277 | 307 | */ |
278 | 308 | void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef * hi2c) |
279 | 309 | { |
310 | + if (murasaki::platform.i2c1->TransmitCompleteCallback(hi2c)) | |
311 | + return; | |
280 | 312 | |
281 | 313 | } |
282 | 314 |
@@ -295,6 +327,8 @@ void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef * hi2c) | ||
295 | 327 | * murasaki::Uart::ReceiveCompleteCallback() function. |
296 | 328 | */ |
297 | 329 | void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef * hi2c) { |
330 | + if (murasaki::platform.i2c1->ReceiveCompleteCallback(hi2c)) | |
331 | + return; | |
298 | 332 | |
299 | 333 | } |
300 | 334 |
@@ -314,6 +348,8 @@ void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef * hi2c) { | ||
314 | 348 | * murasaki::I2c::HandleError() function. |
315 | 349 | */ |
316 | 350 | void HAL_I2C_ErrorCallback(I2C_HandleTypeDef * hi2c) { |
351 | + if (murasaki::platform.i2c1->HandleError(hi2c)) | |
352 | + return; | |
317 | 353 | |
318 | 354 | } |
319 | 355 |
@@ -222,9 +222,10 @@ RCC.USBOutput=48000000 | ||
222 | 222 | RCC.VCOOutputFreq_Value=96000000 |
223 | 223 | SH.GPXTI13.0=GPIO_EXTI13 |
224 | 224 | SH.GPXTI13.ConfNb=1 |
225 | -SPI1.CalculateBaudRate=16.0 MBits/s | |
225 | +SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_256 | |
226 | +SPI1.CalculateBaudRate=125.0 KBits/s | |
226 | 227 | SPI1.Direction=SPI_DIRECTION_2LINES |
227 | -SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate | |
228 | +SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler | |
228 | 229 | SPI1.Mode=SPI_MODE_MASTER |
229 | 230 | SPI1.VirtualType=VM_MASTER |
230 | 231 | USART2.IPParameters=VirtualMode |