ATMEGA4808 with CAN Bus

In This, Part 2 of my CAN Module series( Read Part 1 here), I will look at my recent modification of a previous ATMEGA4808 Development PCB to include CAN bus hardware. The ATMEGA4804 with CAN Bus development board is part of a set of “benchtop development tools” that I designed specifically to design some CAN Bus controlled Gadgets for use in my car…

The PCB is based on a previous project, in which we experimented with alternative chips to replace the ATMEGA328P.

MakerIoT2020 ATMEGA4808 Dev Board
MakerIoT2020 ATMEGA4808 Dev Board

As I was quite happy with the performance of this particular project, I thus decided to use it as the base for the CAN Bus module as well. The Added CAN Hardware adds only a few cm. to the board, keeping it quite compact, although, it will need a complete redesign once I finally get my gadgets finalised 🙂

What is on the PCB ?


The ATMEGA4808 and its supporting components dominate the left side of the PCB, with a USB connector and a CH340N providing the possibility to upload code to the chip using the Optiboot bootloader. I would however caution you, as there seem to be quite a lot of counterfeit CH340N chips floating around, I received two bad batches already, and from reliable suppliers as well… seems there is something fishy going on in the factory?? Answers anyone?

The Right side of the PCB is dedicated to the CAN Hardware, with the MCP2515 and TJA1050 taking centerstage here. While quite old, the MCP2515 is still readily available for the time being and is also quite affordable. Since I had a few left over from previous projects, I decided to once again make use of what I had on hand.

A 120-Ohm termination resistor ( selectable with a jumper), as well as a screw terminal connector, is provided. The board Reset button, as well as a power and user LED ( on D7), is also in that area of the PCB.

All GPIOs on the ATMEGA4808 were broken out onto header pins, to allow for maximum flexibility and access to features and peripherals on the chip.

Schematic and PCB Design

The Schematic, as mentioned before, is based entirely on a previous project of mine, with the CAN Hardware added onto that. ( I remind everyone once again, that this is a “tool” that I designed for myself to help in getting a specific job done. that will mean that it may or may not be very advanced, or suited for other peoples purposes… but , as a general bench module for CAN Bus development based on the ATMEGA4808, it will be perfect – that is what it was designed to do after all )

Schematic, ATMEGA4808 and supporting components
Schematic, ATMEGA4808 and supporting components
Schematic, CAN Bus Hardware, MCP2515 and TJA1050
Schematic, CAN Bus Hardware, MCP2515 and TJA1050

The PCB is a double layer approximately 8.1cm x 3.3cm rectangular module.
6 3.2mm mounting holes are provided.


Manufacturing

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to that will do his/her best to resolve your issue as soon as possible.

Find out more here

Assembly

To save myself time, and ensure that the project is assembled to a high quality standard, I once again opted to have a stencil manufactured in addition to the PCB alone. This is however not strictly required with this board, as the components can still be hand soldered, or solder paste can be manually applied using the method of your choice.

High quality Stainless Stencil
High-quality Stainless Stencil

I used my standard hotplate reflow soldering technique on this board, and it turned out very well indeed, with no solder bridges, making any reworking completely unnecessary, which can in no small part be directly attributed to the super accurate stencil that I used for solder paste application…

Assemble PCB
Assembled PCB

Testing

After assembly, I went through my standard testing ritual, while of course remembering that the ATMEGA4808 is a UPDI programmable chip, which means that you can not just use a USB cable on a brand-new chip…

I uploaded the Optiboot bootloader via that UPDI header, using my own UPDI programmer, that was also a previous project, one that I am very happy to have these days 🙂

A standard blink sketch followed, and then it was time to test the CAN hardware. For this I used Gary J Fowler’s MCP Can Libray ( the same one that I used with the ATTiny1616 a few days ago ), as well as the ATTiny1616 CAN Module that I build a few days ago…

As for the firmware, at this stage, as I am only concerned about testing actual CAN functionality, I made use of the CAN Loopback on both units, and then THe CAN Sender on the ATTiny1616 and the CAN Receiver on the 4808… These sketches are all available in the library examples… so find them there.

Pinouts for the connections to the MCP2515 from the ATMEGA4808 is as follows:

CS is on Pin D7, MISO on D5, MOSI on D4, SCK on D6 and the Interrupt on D10

The ATTiny1616, which I did not mention in part one, is as follows:
CS on D13,MISO on D15, MOSI on D14, SCK on D16 and the Interrupt on D12

Conclusion

Testing went well, with everything working as expected, with the exception of another batch of CH340N chips being suspect… This does however not really bother me, as I am quite comfortable with using UPDI to upload code, as well as using an external USB-to-serial adapter, connected directly to the UART on the ATMEGA4808.

Cosmetically, I made a labelling error on the silkscreen of the CAN Bus connector, swapping Can H and CAN L… once again, this is not a problem to me.

My thanks to PCBWay for another extremely well-made PCB.

CAN Bus support with the ATTiny1616

ATTiny1616 QFN with Can bus support on a breadboard

A short while ago, I started looking at alternatives to the ATMEGA328P ( the chip used in the standard Arduino Uno). That experiment turned out quite well,
with two of the three chips turning out to be useful, the ATTiny1616 and the Atmega 4808 – The ATTiny 202, while working great, has quite a few severe limitations, due to the size of its memory, as well as library support, limiting its actual useful use quite a bit for my purposes.

In this post, which is part of a two-part series, I will look at adding dedicated CAN Bus support to the 1616 and 8408. I am planning to add some gadgets to my car, and would like to have it controlled by a CAN bus interface, and just maybe, interfacing with the CAN bus on the car as well – at least in the future…

This experiment will thus consist of two prototypes with onboard CAN hardware, to be initially used on the bench while building and testing my gadgets – more on them later, if and when they work out the way that I imagine.

What is on the PCB

The ATTiny1616 microcontroller, in a QFN package, has been married to a MCP2515 and a TJA1050. These chips, while old, are still easy to get hold of,
and I have quite a few of them lying around from previous projects. It did thus seem to be a good starting point. The fact that their libraries also works perfectly with the ATTiny1616 and Atmega4808 also went a long way towards selecting them for the project.

The PCB is similar to the ATTiny1616 QFN breakout that I have designed before but with the addition of the CAN-related components.

ATTiny1616 QFN development board with CAN bus, after reflow soldering

Schematic and PCB Design

The schematic is a variation on the earlier breakout PBC, with the addition of the CAN-related components.

ATTiny1616 Schematic - MCU only,
Can bus related components - for use thie the ATTiny1616 MCU


The PCB design has also not changed a lot, I have just added the CAN components to the right hand side of the PCB, and adjusted the routing.

PCB layout design for the ATMEGA1616 with CAN bus Development PCB


3D render of the PCB, with the header pins in non-breadboard configuration – with the CAN bus connector not fitted.

Manufacturing

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to that will do his/her best to resolve your issue as soon as possible.

Find out more here

Assembly

I usually can not wait to receive my creations back from the factory – I mean, how can somebody not get excited about receiving their own PCBs back from the factory, especially if you know they will be of the high quality that I have come to trust with all of my PCBWay orders?

This is especially true of the smaller PCBs, as well as those with smaller-sized QFN components, with this board definitely not being an exception.

ATTiny1616 QFN Dev board with Can Bus, in packaging - straight from the factory
PCBs in factory packaging
PCBs in protective wrapping, after opening
PCBs in protective wrapping, just after opening the package
Closeup view of the top side of the PCB
Closeup view of the top side of the PCB

This PCB once again requires the use of a stencil, to accurately apply just the right amount of solder paste to the pads, especially the small QFN package pads of the ATTiny 1616…

High quality stainless steel, laser cut stencil. High accuracy. Definitely worth the investment
High-quality stainless steel, laser cut stencil.

Stencils, at least from my point of view, can be a controversial subject, with some hobbyists arguing that they are not worth the additional expense… I do however believe that they actually save you a lot, in time that you don’t waste on reworking a PCB due to solder bridges, in the correct amount of solder paste that is applied, in the correct thickness, and also time not wasted on the cleanup of the mess that can result from manually applying solder paste.

After solder paste application, all the components are placed in their correct positions, ready to be reflow soldered.
PCB ready for reflow soldering, after manually placing the components in their respective places

The PCB is now reflow soldered with a hot plate, and allowed to slowly cool down afterwards, to reduce thermal shock damage to the joints, that may result from a too-quick cooldown cycle. While I do not own a dedicated reflow oven, the hotplate that I use, seems to match the reflow profile ramp-up of my solder paste, and most of the components perfectly. After achieving a complete solder melt, at about 223 degrees C, I usually switch of the hot plate, and carefully move the PCB towards the edge of the unit, that area is usually a bit cooler than the centre. leaving it there for about 5 to 8 minutes, allow the solder to slowly solidify, after which I remove it and place it on a silicone mat to cool completely.

Through-hole component soldering, and testing

The next step is soldering all the through-hole components, usually header pins and connectors into their respective places. The board is then placed onto a solderless breadboard, and various test sketches are uploaded via a homemade UPDI programmer.

These include the infamous blink sketch, to make sure the chip is alive and survived the reflow soldering. That is followed by a CAN loopback test, and then the actual CAN firmware… I make use of the excellent MCP Can library from Garry J Fowler, as well as the megaTinyCore Arduino core, from Spence Konde.

My thanks to both of these gentlemen, for their excellent and easy-to-use software. A special shoutout to Garry J Fowler, since his MCP Can library correctly releases the CE pin of the device when not in use, thus not locking up the spi bus. [ This is something that many other libraries do not bother to care about ] …

Conclusion

This was once again a fun project to design and assemble. The real testing and development can now start at full speed, as this is just meant to be a tool, with a further revision later down the line. It does of course help a whole lot that I can completely trust my PCB manufacturer, PCBWay, to deliver my PCBs to me EXACTLY as I designed them, and at extremely high quality and precision! Thank you for that!

Easy to use CAN-BUS Module with Relay, LiPo Battery Backup

Can Relay Module running on battery power

CAN-Bus allows us to add a lot of devices to a single bus (theoretically up to 127, with a practical limit of about 110). It was logical to decide to use CAN-BUS for communication between my LoRa-CAN Module and remote nodes in my ongoing farm telemetry system. In a previous project, I introduced the LoRa-CAN Gateway, which will be used to send/receive messages from the master control unit, the SX127x-RA-02-Module.

Today, I will focus on the design of the node device, an Arduino compatible CAN Relay Module PCB, with a built-in, CAN Controller and Transceiver ( MCP2515 and TJA1050 ), and the option to be powered from a LiPo battery (18650 or Single 3.7v Lipo cell), with charging provided by an MH-CD42 Module, similar to that used in the SX128x project mentioned above. The Module can also be powered directly from up to 12v DC by placing Jumper H2 in the V-REG position…

As mentioned in a previous project, the MH-CD42 module can provide up to 2A of current to charge a battery and provide 5V DC on a direct bypass circuit to power the rest of the circuit while the battery is being charged. This feature makes it ideal for my intended use, as I would only be needing battery power at night when the off-grid solar powered inverter is not actively charging the main batteries, and providing 220v AC.

Can Relay Module Top view

The CAN Relay Module PCB was designed to be as compact as possible, with a total footprint of the standard Arduino UNO. As space was at a premium, and to ensure that there are the absolute minimum additional components that will consume power when operating from the battery, I have not included any USB-to-Serial converters onboard. Firmware can be uploaded with an AVRASp, USBASP, Arduino as ISP or even an external USB-to-Serial converter ( providing that you load a bootloader into the Atmega Chip).

Can Relay Module side view

All of the unused GPIO pins on the ATMEGA chip is broken out into headers, with the exception of D10 ( which is used as CE/SS on the MCP2515 CAN controller), D9 which is connected to the Interrupt from the MCP2515, and D4, which is used to control the onboard Relay.

Can Relay Module with LiPo cell and MH-CD42 Module

The MH-CD42 Module, and LiPo or 18650 Battery are completely optional, The device can function without these, by moving the H2 jumper to the VREG position as already mentioned above. This will divert the DC Voltage(Up to 12v) from the DC input adapter to the build-in 5v LDO voltage regulator to power the device.

If you place the H2 Jumper in the VBAT position, you need to install the MH-CD42 module to provide power to the rest of the PCB, as well as keep the LiPo battery or 18650 Cell charged…

Please NOTE:

When the MH-CD42 module is in use, the total DC input voltage through the DC input adapter SHOULD NOT exceed 5.5v DC! This is a limitation in the operating parameters of the MH-CD42 module. Not paying attention to this will result in damage to the MH-CD42 Module.

You could also power the module with REGULATED 5v DC, directly from any 5v header pin. Please note that in this case,

1) The battery won’t be charged.

2) The LDO regulator will not be in operation.

The Microcontroller

The CAN Relay Module can use any of the ATMEGA8a/88/168/328 AVR microcontrollers, as the pinout is identical. I believe this is an advantage, especially with the current chip prices, where my last quote for an ATMEGA328P-AU was 69$USD!!!! This is in comparison to the 4 to 5 USD each for an ATMEGA8a or ATMEGA168 ( We must also remember though that the 328p is very well known, and thus have higher demand. The 8a/88 or 168 are less well known, have much less memory and flash area, and will thus be cheaper. A word of action though, I had strange issues with I2C on the Atmega8a with Mini core, to such an extent that I2C does not work at all?

If you plan to use I2C on this board, install a 328p right from the start, and save yourself a lot of headaches!

Can Relay Module Schematic Page 1

This is the Relay driver circuit. As you can see, it is optically isolated, and active LOW. This means that you have to pull D4 LOW to energise the relay. Also note that, although the relay is optically isolated from the microcontroller, the coil is NOT galvanically ISOLATED. The load, which is magnetically switched, will be truly galvanically isolated, providing of course that you don’t do something silly like using a common ground to the PCB as a common on the relay…

Can Relay Module Schematic Page 2

This is the Processor and Power-supply schematic. The circuit is basically a standard Arduino Nano, with modifications for the CAN Controller on the next schematic page. Note that the MH-CD42 is not shown on the schematic. The VBAT net connects directly to the VIN pin on the unit, with the BAT net connecting to the positive of the battery. VOUt-5v from the module goes directly to the 5v net. All grounds are commoned.

This is the CAN Controller and Transceiver circuitry. The MCP2515 connects directly to the SPI bus on the microcontroller via D13, D12 and D11, with D10 as CE/SS and D9 as Interrupt or IRQ. It is important to note that although the MCP2515 is a 3v capable device, the TJA1050 Can transceiver is 5v only. This prevents us from running the PCB at 3v unless, of course, we change the TJA1050 out for a 3v capable device…

CODE

The board has been extensively tested with Cory J Fowler’s mcp_can Arduino Library. It works very well indeed.

As I am currently working on the final integration of the two modules, I am not yet ready to publish my final code, showing the operation between the CAN-Bus and LoRa-to-CAN Gateway device in this post. Once I am happy that all issues are definitively sorted out, I will publish my code.

This PCB was manufactured at PCBWAY. The Gerber files and BOM, as well as all the schematics, will soon be available as a shared project on their website. If you would like to have PCBWAY manufacture one of your own, designs, or even this particular PCB, you need to do the following…
1) Click on this link
2) Create an account if you have not already got one of your own.
If you use the link above, you will also instantly receive a $5USD coupon, which you can use on your first or any other order later. (Disclaimer: I will earn a small referral fee from PCBWay. This referral fee will not affect the cost of your order, nor will you pay any part thereof.)
3) Once you have gone to their website, and created an account, or login with your existing account,

4) Click on PCB Instant Quote

5) If you do not have any very special requirements for your PCB, click on Quick-order PCB

6) Click on Add Gerber File, and select your Gerber file(s) from your computer. Most of your PCB details will now be automatically selected, leaving you to only select the solder mask and silk-screen colour, as well as to remove the order number or not. You can of course fine-tune everything exactly as you want as well.

7) You can also select whether you want an SMD stencil, or have the board assembled after manufacturing. Please note that the assembly service, as well as the cost of your components, ARE NOT included in the initial quoted price. ( The quote will update depending on what options you select ).

8) When you are happy with the options that you have selected, you can click on the Save to Cart Button. From here on, you can go to the top of the screen, click on Cart, make any payment(s) or use any coupons that you have in your account.

Then just sit back and wait for your new PCB to be delivered to your door via the shipping company that you have selected during checkout.