dave3891
Newbie level 3
- Joined
- Oct 23, 2010
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,306
I have a FPGA pulse generator design that is connected to a STM32 board with SPI and I am having a strange problem with sending / receiving data.
The basic operation is that I send a quantity of pulses to the FPGA and then a frequency to pulse them at. The FPGA then counts them down as it pulses and I can read the remaining quantity back any time.
Sending the data seems to work as planned, but the receiving is quite strange.
I setup a test data send with the following:
And then read it back on the M3 with this code:
When I do this it returns the 123456789 as expected.
But if I send to a register and read it back, it comes back in a strange order. eg:
If I send 200 (hex 00 00 00 C8) it comes back as 3368550400 (C8 C8 00 00)
If I send 123 (00 00 00 7B) it comes back as 2071658496 (7B 7B 00 00)
But the numbers that I send appear to operate the FPGA as expected.
Here is the receive code on the FPGA:
And here is the code that sends it from the M3:
I am really lost with why the static set number from the FPGA sends correctly but reading back a previously send number that operates the FPGA as expected, does not read properly.
Any ideas would be appreciated.
Thanks
Dave
The basic operation is that I send a quantity of pulses to the FPGA and then a frequency to pulse them at. The FPGA then counts them down as it pulses and I can read the remaining quantity back any time.
Sending the data seems to work as planned, but the receiving is quite strange.
I setup a test data send with the following:
Code:
// Set outgoing bytes
always @(posedge clk) begin
if(SSEL_startmessage) begin
sendTest <= 123456789;
sendmem[0] <= sendTest[31:24];
sendmem[1] <= sendTest[23:16];
sendmem[2] <= sendTest[15:8];
sendmem[3] <= sendTest[7:0];
end
end
And then read it back on the M3 with this code:
Code:
for ( i = 0; i < 4; i++ )
{
// Data out
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1, src_addr[i]);
// Data in
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
inBuff[i] = SPI_I2S_ReceiveData(SPI1);
for(delay=0; delay<SPIDELAY; delay++);
}
GPIO_WriteBit(GPIOC, GPIO_Pin_6, 1); // Set SSEL pin high
remaining |= (inBuff[0] << 24);
remaining |= (inBuff[1] << 16);
remaining |= (inBuff[2] << 8);
remaining |= (inBuff[3]);
return remaining;
When I do this it returns the 123456789 as expected.
But if I send to a register and read it back, it comes back in a strange order. eg:
If I send 200 (hex 00 00 00 C8) it comes back as 3368550400 (C8 C8 00 00)
If I send 123 (00 00 00 7B) it comes back as 2071658496 (7B 7B 00 00)
But the numbers that I send appear to operate the FPGA as expected.
Here is the receive code on the FPGA:
Code:
if(SSEL_endmessage) begin
// Read the first byte for the command
// 0x01 = position command
// 0x02 = Velocity command
if (mem[0] == 1) begin
xcmd <= {mem[1], mem[2], mem[3], mem[4]};
ycmd <= {mem[5], mem[6], mem[7], mem[8]};
zcmd <= {mem[9], mem[10], mem[11], mem[12]};
load <= 1;
end
else if(mem[0] == 2) begin
frequency <= {mem[1], mem[2], mem[3]};
loadFreq <= 1;
end
end
And here is the code that sends it from the M3:
Code:
uint32_t xCommand = 123;
uint32_t yCommand = 200;
uint32_t zCommand = 200;
src_addr[0] = 1; //0x01 for command 0x02 for velocity
src_addr[1] = xCommand >> 24; src_addr[2] = xCommand >> 16; src_addr[3] = xCommand >> 8; src_addr[4] = xCommand;
src_addr[5] = yCommand >> 24; src_addr[6] = yCommand >> 16; src_addr[7] = yCommand >> 8; src_addr[8] = yCommand;
src_addr[9] = zCommand >> 24; src_addr[10] = zCommand >> 16; src_addr[11] = zCommand >> 8; src_addr[12] = zCommand;
SPISend((uint8_t *)src_addr, 13);
I am really lost with why the static set number from the FPGA sends correctly but reading back a previously send number that operates the FPGA as expected, does not read properly.
Any ideas would be appreciated.
Thanks
Dave