some problems with spi data transmission

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

some problems with spi data transmission

Post by gilanetugila »

Good afternoon, Benj! I tried to do a test on the work of spi, I have this interface in the program does not work. When trying to send byte data, a sign about the presence of errors appears. And when trying to accept data, an error occurs when converting to code. I looked through several topics on spi, tried to configure the spi ports so that one atmega8 worked as a master and the other as a slave - but it didn't help in any way, all the same errors. If you have the opportunity and time, can you help me with solving these problems.Program version 8.2.2.15

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

Can you post your file? Without it it's pretty much impossible to help.

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Attached files with tests for sending and receiving data over the spi bus.
Attachments
get_spi_data.fcfx
in this file, an error pops up during compilation:get_spi_data.c:(.text.main+0x3c): undefined reference to `FC_CAL_SPI_Slave_RxByte_1'

Error returned from [avr-gcc.exe]

C:\Program Files (x86)\Flowcode\Common\Compilers\avr\batchfiles\avra.bat reported error code 1

Autoclose turned off
(10.66 KiB) Downloaded 560 times
test_send_SPI.fcfx
in this file, an error sign appears at startup
(10.14 KiB) Downloaded 576 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

Sorry for brief reply, just heading out.

Is there a reason you are using C-code to set pins to be used for SPI? Flowcode takes care of this automatically.

In your receive, how do you know there is data to be collected?

If you look in the WiKi you will see some examples of what you are trying to do

https://www.flowcode.co.uk/wiki/index.p ... Interface)

However the example uses a different chip that has SSP Interrupts, you may need to either create a custom/ timer interrupt or use the CS pin to signal that a transmission is imminent.

Generally speaking, when sending you would

Toggle CS
Wait 10uS or so (may not be necessary depending on target)
Send Data
Toggle CS

Do you have a scope or a logic analyser (even a really cheapo can help)? These can be invaluable when debugging SPIissues.

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Thanks for the wiki link. But to be honest, nothing is clear! I never thought that the port value could take some byte number other than 0 and 1! And there, in the first example, a slave loop without anything (without any program code)-it is also unclear why this is done. The fact that I used an insert in the c language - I looked at it in the videos on SPI, I tried using standard program tools to do initialization and enable CS before and inside the subroutine. I can't tell if this spi module is working or not, an error just pops up. And when working in slave mode, no code is generated at all. You correctly noticed that you need to check, at least using virtual tools. I'll try it today, at least for master mode. Do you have the opportunity to explain how the highlighted icons work in the drawing of the program taken from the wiki. Or maybe it's somehow simpler and to make it clearer, you can do it?
Attachments
2.JPG
2.JPG (45.14 KiB) Viewed 1773052 times
1.JPG
1.JPG (54.73 KiB) Viewed 1773052 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

Shopping is my least favourite activity, well unless it's for cars / geek toys / test equipment / beer etc :)

My phone isn't the best to reply with but I think there is some confusion. A single digital port (e.g. B0 / B1 / B2 etc) can only have the value of 1 or 0, however the entire port is 8-bits wide (assuming 8-bit micro and the port has 8-bits assigned) and can be referenced in it's entirety.

B7 B6 B5 B4 B3 B2 B1 B0

This equals in Binary

128 64 32 16 8 4 2 1

So an entire Port can input/output a range of values between 0 and 255 if 8-bits wide.

If you use the "Output" component you assign a value or a variable to either a single Bit, multiple bits using a Mask, or the entire Port.

So to set Port B7 to "1" I could do the following

Use the value "1" and set Single Bit (B7)

or use value "128" and set Port

Note though that setting 128 to entire Port will set B7 to "1" and set B6 to B0 as "0".

Similarly for Input. Assume Port B1 and B2 were high (a value of 1 on the pins) with the other pins low (0)

If I read single Bit B2, or single Bit B1 I would get the value of "1". However if I read the entire Port I would get the value 6.

I would first ensure I'm actually transmitting valid data before worrying about the receive, but in answer to your questions:

You have two charts within the program called Macros, Main and SPI_Slave. Main is generally where the bulk of the work is done with branches for specific tasks such as Interrupts etc.

The Initialise Macro's do all the hard work of configuring the chip to undertake whatever (SPI/RS232/Display/whatever) based on the component properties you entered.

The Interrupt on SSP configures the chip to react whenever an SPI transmission is received. It monitors the associated flag and branches to a predefined Macro if set. In this case SPI_Slave (note that not all chips have the ability to interrupt on SSP). Whenever an incoming message arrives it will automatically jump to the SPI_Slave to process then return to Main.

The Loop is an endless loop (in this case doing nothing) used to keep the chip circling doing something until an Interrupt occurs, in which case it then branches to the assigned Macro. You could have it do whatever you wanted instead. It could display a value, or read a sensor, anything really. Point being the Main macro is busy doing something else and only branches when the interrupt occurs.

When the Interrupt occurs we branch to the SPI_Slave Macro, because the interrupt is set for SSP it only branches upon receipt of a transmission so we know we have something to fetch.

We use the GetChar macro to get the value and we assign it to the variable "in"
Then we output the binary value of "in" as an 8-bit value to the entire Port B (e.g. 10010110 or 11001101 etc) with Port B7 being the MSB and B0 the LSB.
Next (for reasons not known but assume as a test) we transmit the value of "in"+5 back out on the SPI interface.

Hope this helps.

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

I get it, thanks. I just haven't come across such a representation before. There was once an idea to program a variable with binary code with small switches, but then I abandoned this idea, since there were too many variables, and there was not enough place to cram it all in. Therefore, I decided to try to do this using spi. So we managed to make an electronic simulation and look at it with a virtual oscilloscope. Unfortunately, the view differs from the theoretical one-there are shifts in the graphs, but this is most likely due to delays and restarting the SS bus. I tried to send the number 4 at a frequency of 8 MHz and 1 mhz and the number 201 at a frequency of 8 mhz. I was able to examine the graphs at a frequency of 8 mhz in more detail.It looks like spi is working! but for some reason, when sending the number 4, the polarity of the signal is positive, and when sending the number 201, the polarity of the signal is negative. I will be able to check the operation of spi in slave mode on Monday after 16 o'clock. I have to go to work tomorrow.
Attachments
8MGr,yellou-SS,blue-MOSI,red-SCK,send_201.jpg
8MGr,yellou-SS,blue-MOSI,red-SCK,send_201.jpg (150.96 KiB) Viewed 1773043 times
8MGr,yellou-SS,blue-MOSI,red-SCK,send_4.jpg
8MGr,yellou-SS,blue-MOSI,red-SCK,send_4.jpg (121.54 KiB) Viewed 1773043 times
1MGr,yellou-SS,blue-MOSI,red-SCK,send_4.jpg
1MGr,yellou-SS,blue-MOSI,red-SCK,send_4.jpg (142.43 KiB) Viewed 1773043 times

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Slightly changed the program -added delays and restart of the CS bus (according to your recommendations) and added lcd1602 for clarity.
Attachments
test_send_SPI.fcfx
(13.46 KiB) Downloaded 606 times
8MGr,yellou-SS,blue-MOSI,red-SCK,send_201_2.jpg
8MGr,yellou-SS,blue-MOSI,red-SCK,send_201_2.jpg (156.51 KiB) Viewed 1773043 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

I see you seem to be simulating in Proteus. That's not something I'm over familiar with, but note that when simulating any microcontroller in any software you add in an extra level of "pain" :)

Many other factors now add their toll to what you hope to see, so just because something doesn't seem to work in your simulation, that doesn't always necessarily mean it doesn't work for real.

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good day! Yes, I regularly come across the fact that if something works in the proteus program does not mean that it will work in a real project and if the project works on a real board, it does not mean that it will work in the proteus program.

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good day! I tried to make a program for the slave spi mode in flowcode, as in the lesson on the wiki site, an error pops up when trying to broadcast the program. It seems that this module does not work in the program or it does not exist. And here it doesn't matter how I do the project on a real board or in a simulation program. In both cases, a program is needed there, and it does not compile. Can you take a look at what the problem is.? I tried to report the error through the "help" program menu, but it does not work for me and does not send messages.
Attachments
SPI_error_slave.JPG
SPI_error_slave.JPG (140.8 KiB) Viewed 1772979 times
get_slave_primer_wiki.msg.txt
(3 KiB) Downloaded 605 times
get_slave_primer_wiki.fcfx
(11.58 KiB) Downloaded 567 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

Busy over the next couple of days so my replies may be limited.

I'm not very familiar with your chip, however I downloaded your chart and it seems that it should work providing the interrupt is called at the correct time. Without knowing what it is connected to and how that relates to an incoming SPI transmission I can't really comment regarding that.

Your chart did compile without errors for me though. Have you updated all components?

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Thank you for paying a little attention to me and my program! Yes, I have been updated recently, maybe 1-2 weeks, a lot of updates have come. But I haven't seen any updates for the spi interface. After the update, for some reason, the connection disappeared-I can't ask for help or try to download more updates.
Attachments
connection error.JPG
connection error.JPG (68.76 KiB) Viewed 1772970 times
failed to send the report.JPG
failed to send the report.JPG (109.84 KiB) Viewed 1772970 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

Guessing you are using an "educational" license? I am not familiar with that version of Flowcode so can't help regarding the messages you are seeing. It looks like it has features different to the other versions.

Whilst I have FC v5 - v10 on my machine, I only have a license for your chip in v9 onwards, and as mentioned it does compile OK for me using v10, so the code itself is valid (albeit not doing as you wish). One thing to note though is that your are using INT0 to call your macro, but you don't document what is connected to the INT0 pin or what will trigger the interrupt telling the chip to look for an incoming signal.

The CS pin is normally used as Chip Select, used to inform the unique slave device that the transmission is for it. The Master device CS would connect to the Slave CS. Having only used SPI as Master, I don't yet know if the FC Slave Component monitors the pin automatically or if you need to include further code to detect.The WiKi examples all use a SSP interrupt which not all chips have....

As mentioned previously, the normal sequence when transmitting is

Toggle CS from High to Low (informs Slave that the forthcoming transmission is for it)
Wait a few uS (dependent on target)
Send Data
Toggle CS from Low to High (ends transmission. Many slave devices only process received data when this pin returns to High)

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good morning! I have a professional license for the flowcode program. Today I edited the antivirus settings, the flowcode program website page appeared on the primary page. I understand that the connection with the site has been restored. I tried to update again, but nothing else came. I created a new program for spi slave using the example from the wiki site, but the example came out somewhat clumsy. As you correctly noticed, the ss pin is used there for interrupting. For atmega 8, I did not find such an option and decided to use one of the pins for an external interrupt INT0 or INT1. Thanks to your letter, I realized that I did not correctly write a program in which an interrupt should be used. There was another option to create an interrupt yourself, but you need to write code. What I can't do. For this reason, I would like to know about the possibility of using an interrupt in the case of spi slave based on the capabilities of the flowcode program, without inserts in the C language, if possible.And even if the flowcode program is made incorrectly, it is still obliged to write the code in C, just the device will not work. And in my case, she doesn't write in C. Maybe you can compare the code of your atmega8 spi slave element with my element from the program I sent you. Or did you not rewrite it, but immediately downloaded and started the broadcast in the c code.?Maybe you have a connection with the technical support of the flowcode program and they can give you some useful advice.

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

Just heading out.

AV.... many posts regarding issues with such, although not so many now. It can really screw things up. Glad to hear you have it resolved.

I didn't rewrite, I just downloaded your code which compiled to both C and Hex without any issue. When you update, remember to check "full database" instead of just "files in use" to ensure everything is up to date.

I'm not a programmer, I'm a Flowcoder so my "C" isn't too great and if I did write code I'd strongly advise it be checked before use :lol: The datasheet for the chip is quite helpful though, explaining which flags get set etc.

I'll try and have a play with SPI Slave, but it probably won't be until later in the week.

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good afternoon! I recently looked at the updates that I downloaded earlier, there were updates for the spi bus and for the spi slave. But something went wrong probably. Does the spi slave module necessarily need an interrupt to work? Or if there is no interruption, suppose the slave module instead of some values of the variable a (in my example) will receive a =0 and it will overwrite the previously downloaded values a>0 in the buffer? I will wait well, maybe you will get something by receiving and transmitting data from atmega 8 over the spi bus.
Attachments
обновление spi1.JPG
обновление spi1.JPG (62.51 KiB) Viewed 1772949 times
обновление spi.JPG
обновление spi.JPG (68.83 KiB) Viewed 1772949 times

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good evening! I wanted to ask - did you manage to find a solution to the problem of transmitting and receiving data via the spi interface when using the atmega8 controller?

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

I've only just obtained the necessary licences to allow me to use that chip in v8.

I'll try and check in the next day or two.

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good evening! I asked one specialist, he says there is a problem with the atmega8 slave spi module. When transferring data from one atmega8 to another atmega8, I recommended trying to use master in reception mode instead of slave. But with such a connection, the atmega8 that works for transmission, its CS or SS bus must be on a different pin than the standard hardware one. I tried, but I didn't get anything good. But again, I was guided by the oscilloscope from the flowcode and proteus programs. But you once wrote that focusing on simulation in the program is a bad idea. If there was at least some minimal positive result, I would try to solder, but so far there is nothing to focus on. Have you tried transmitting data on pic controllers, how does everything turn out easily there? and there is an interrupt on any controller , as in the wiki example ?

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

Sorry to be brief, just heading out.

Using PICs I've had lot's of "fun" with SPI and it rarely works first time for me, but that is because I've done something dumb :oops:

I use a logic analyser to monitor my pins so I can see in real-time what is happening and it will also decode too. Even the cheap ones available on Amazon or the like are worth having as they provide so much information. With the analyser I usually find the problem without too much trouble.

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good evening! And that it allows you to see what is happening on each pin or decrypts the signal, let's say you sent the number 5 and it recognizes it, or will it be graphs in the form of alternating logical zeros and ones? In the attached files I send an example of which I wrote earlier.
Attachments
test_send_SPI_3.hex
(4.2 KiB) Downloaded 588 times
get_spi_master.fcfx
(12.09 KiB) Downloaded 615 times
test_send_SPI_3.fcfx
(12.82 KiB) Downloaded 619 times

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

In the attached files I send an example of which I wrote earlier.
Attachments
91.jpg
91.jpg (151.5 KiB) Viewed 1772787 times
912.JPG
912.JPG (69.54 KiB) Viewed 1772787 times
get_spi_master.hex
(4.17 KiB) Downloaded 561 times

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

In the attached files I send an example of which I wrote earlier.
Attachments
9.jpg
9.jpg (150.47 KiB) Viewed 1772787 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

Whilst it is good you are getting traces I still think you have issues with CS/SS pin. I would expect it to idle high only going low for the duration of transmission, and as I mentioned earlier certain Slaves won't actually do anything with the incoming data until the pin returns to high.

Yes, even the cheapo logic analysers will decode the signals and will display whatever value(s) it sees. They will typically include UART / SPI / i2c 1-wire etc capabilities and if working with hardware they are invaluable.

I hope to check on hardware later in the week.

Regards

Post Reply