Hi guys,
im new using the WaveForm Buffer from ADE, and facing a challenge about getting the values from the buffer and using them for another stuff, like showing on display.
Currently, when i start my firmware, my hole MCU stops work, i thinks is because the amount of data im triyng to transmit via UART, but it's probably just bad software architecture.
I'll leave my code in the end just in case anyone is interested. If you could share your solution with me so I can study the case, I'd be very grateful!!
Im setting the WFB_CFG with this specs (I'm not setting anything else besides it, no trigger or interruptions):
cfg |= (1 << 5); /* WF_CAP_SEL = 1 */ cfg |= (0 << 6); /* WF_MODE = 00 */ cfg |= (0 << 8); /* WF_SRC = 00 (sinc4) */ cfg |= (0 << 12); /* WF_IN_EN = 0 */ cfg |= (0x0); /* BURST_CHAN = 0000 */
void ADE9000_ReadPage_BurstRead(uint8_t page)
{
uint16_t baseAddr = ADDR_WFB_BASE + (page * PAGE_WORDS);
uint32_t buffer[PAGE_WORDS];
int word_in_sample;
ADE9000SPI_BurstRead(baseAddr, buffer, PAGE_WORDS);
for(int i = 0; i < PAGE_WORDS; i++)
{
word_in_sample = i % 8;
if(word_in_sample <= 5)
{
ADE9000_GetRealValues(buffer[i],word_in_sample);
}
}
}
void ADE9000SPI_BurstRead(uint16_t startAddr, uint32_t *buffer, uint16_t nWords)
{
startAddr = (((startAddr <<4) & 0xFFF0) + 8);
uint16_t txData, rxData;
uint16_t high, low;
HAL_GPIO_WritePin(CS_SPI1_GPIO_Port, CS_SPI1_Pin, GPIO_PIN_RESET);
txData = startAddr;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t*)&txData, (uint8_t*)&rxData, 1, HAL_MAX_DELAY);
for(uint16_t i = 0;i < nWords;i++)
{
txData = 0x0000;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t*)&txData, (uint8_t*)&high, 1, HAL_MAX_DELAY);
HAL_SPI_TransmitReceive(&hspi1, (uint8_t*)&txData, (uint8_t*)&low, 1, HAL_MAX_DELAY);
buffer[i] = ((uint32_t) high << 16) | low;
}
HAL_GPIO_WritePin(CS_SPI1_GPIO_Port, CS_SPI1_Pin, GPIO_PIN_SET);
}
void ADE9000_GetRealValues(uint32_t raw32, int word_in_sample )
{
int32_t realValue;
int32_t shifted = (int32_t)(raw32 >> 4);
if(shifted & (1 << 23)) shifted |= 0xFF000000;
switch(word_in_sample)
{
case 0:
/* IA */
realValue = (int32_t) shifted * I_SCALE;
//Export realValue via UART
break;
case 1:
/* VA */
realValue = (int32_t) shifted * V_SCALE;
//Export realValue via UART
break;
case 2:
/* IB */
realValue = (int32_t) shifted * I_SCALE;
//Export realValue via UART
break;
case 3:
/* VB */
realValue = (int32_t) shifted * V_SCALE;
//Export realValue via UART
break;
case 4:
/* IC */
realValue = (int32_t) shifted * I_SCALE;
//Export realValue via UART
break;
case 5:
/* VC */
realValue = (int32_t) shifted * V_SCALE;
//Export realValue via UART
break;
default:
break;
}
}
Sorry, for so much code...